home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / CWL2A_2.ARJ / MANUAL.DOC
Text File  |  1991-11-12  |  605KB  |  18,755 lines

  1.                            THE C WINDOW LIBRARY
  2.                     (c) Copyright P. A. McKenzie 1990, 1991
  3.                            All Rights Reserved
  4.  
  5.                                Version 2.0
  6.  
  7.  
  8.                        T A B L E   O F   C O N T E N T S
  9.   INTRODUCTION ....................................................... 1
  10.      Defining Windows ................................................ 1
  11.      Properties of Windows ........................................... 1
  12.      Writing to Overlapping Windows .................................. 1
  13.      Window Ranks .................................................... 2
  14.      Detection of Video Hardware ..................................... 2
  15.      Window Coordinates .............................................. 2
  16.      Video Attributes ................................................ 3
  17.      Direct Screen Writes and BIOS Screen Updates .................... 4
  18.      Video Paging .................................................... 5
  19.      Error Codes ..................................................... 6
  20.      Window Manager .................................................. 7
  21.  
  22.  
  23.   MANDATORY FUNCTIONS AND HEADER FILES ............................... 8
  24.      WindowInitializeSystem() ........................................ 8
  25.  
  26.  
  27.   CREATING WINDOWS ................................................... 9
  28.      The WINDOW structure and WPOINTER structure pointer ............. 9
  29.      WindowSaveInitial() ............................................. 9
  30.      WindowInitialize() .............................................. 10
  31.      CREATE_VIDEO_ATTRIBUTE() macro .................................. 11
  32.      Box types ....................................................... 11
  33.  
  34.  
  35.   OPENING WINDOWS FOR READING AND WRITING ............................ 13
  36.      WindowOpen() .................................................... 13
  37.  
  38.  
  39.   DISPLAYING WINDOWS ................................................. 14
  40.      The WindowDisplay() function and Explosion Effects .............. 14
  41.      Displaying Multiple Windows ..................................... 18
  42.  
  43.  
  44.   CLOSING WINDOWS .................................................... 20
  45.      WindowClose() ................................................... 20
  46.      WindowFree() .................................................... 22
  47.      WindowCloseAll() ................................................ 22
  48.      WindowFreeAll() ................................................. 23
  49.  
  50.  
  51.   CENTERING WINDOWS ON THE SCREEN .................................... 24
  52.      WindowCenter() .................................................. 24
  53.  
  54.  
  55.   CHANGING WINDOW CHARACTERISTICS .................................... 26
  56.      WindowChangeTextAttribute() ..................................... 26
  57.      WindowChangeBorderAttribute() ................................... 27
  58.      WindowDrawBorder() .............................................. 28
  59.      WindowRemoveBorder() ............................................ 29
  60.      WindowResizeHeight() ............................................ 29
  61.      WindowResizeWidth() ............................................. 30
  62.  
  63.  Page i                     The C Window Library                    Page i
  64.                        T A B L E   O F   C O N T E N T S
  65.   WRITING TEXT TO WINDOWS ............................................ 33
  66.      Null Terminated Write Functions ................................. 33
  67.         WindowWriteString() .......................................... 33
  68.         WindowWriteStringAttr() ...................................... 34
  69.         WindowWriteCenterString() .................................... 35
  70.         WindowWriteCenterStringAttr() ................................ 36
  71.         WindowWriteStringCC() ........................................ 36
  72.         WindowWriteStringCCAttr() .................................... 37
  73.         WindowWriteStringRJ() ........................................ 38
  74.         WindowWriteStringRJAttr() .................................... 39
  75.      Length Controlled Write Functions ............................... 40
  76.         WindowWriteCharacters() ...................................... 40
  77.         WindowWriteAttributes() ...................................... 41
  78.         WindowWriteCharAndAttr() ..................................... 42
  79.         WindowWriteCharactersAttr() .................................. 43
  80.         WindowWriteRepeatAttribute() ................................. 44
  81.         WindowWriteRepeatCharacter() ................................. 45
  82.      Formatted Write Functions ....................................... 46
  83.         Where output is placed in the window ......................... 46
  84.         WindowSetWrap() .............................................. 46
  85.         WindowPrintf() ............................................... 47
  86.         WindowPrintfAttr() ........................................... 48
  87.  
  88.  
  89.   WRITING TITLES TO WINDOWS .......................................... 49
  90.      WindowTitleTop() ................................................ 50
  91.      WindowTitleBottom() ............................................. 51
  92.      WindowTitleTopAttr() ............................................ 52
  93.      WindowTitleBottomAttr() ......................................... 53
  94.  
  95.  
  96.   READING CHARACTERS AND ATTRIBUTES FROM WINDOWS ..................... 55
  97.      WindowReadCharacters() .......................................... 55
  98.      WindowReadAttributes() .......................................... 56
  99.      WindowReadCharAndAttr() ......................................... 57
  100.  
  101.  
  102.   HIDING WINDOWS ..................................................... 59
  103.      WindowHide() .................................................... 59
  104.  
  105.  
  106.   CREATING COPIES OF A WINDOW ........................................ 61
  107.      WindowCopy() .................................................... 61
  108.  
  109.  
  110.   SCROLLING TEXT IN WINDOWS .......................................... 63
  111.      WindowScroll() .................................................. 63
  112.      WindowScrollRegion() ............................................ 64
  113.      WindowScrollAttr() .............................................. 65
  114.      WindowScrollRegionAttr() ........................................ 66
  115.  
  116.  
  117.  
  118.  
  119.  Page ii                    The C Window Library                    Page ii
  120.                        T A B L E   O F   C O N T E N T S
  121.   CLEARING WINDOWS ................................................... 68
  122.      WindowClear() ................................................... 68
  123.      WindowClearAttr() ............................................... 69
  124.      WindowClearRegion() ............................................. 69
  125.      WindowClearRegionAttr() ......................................... 70
  126.  
  127.  
  128.   WRITING WINDOW CONTENTS TO A FILE .................................. 72
  129.      WindowWriteTextToFile() ......................................... 72
  130.  
  131.  
  132.   SHADOWING WINDOWS .................................................. 74
  133.      WindowDrawShadow() .............................................. 74
  134.      WindowRemoveShadow() ............................................ 76
  135.  
  136.  
  137.   SEE-THRU WINDOWS ................................................... 77
  138.      WindowMakeSeeThru() ............................................. 77
  139.      WindowMakeNormal() .............................................. 78
  140.  
  141.  
  142.   MOVING AND SLIDING WINDOWS ......................................... 79
  143.      WindowMove() .................................................... 79
  144.      WindowSlide() ................................................... 80
  145.  
  146.  
  147.   CURSOR POSITIONING IN WINDOWS ...................................... 81
  148.      Cursor Maintenance in The C Window Library ...................... 81
  149.      Creating Cursor Shapes .......................................... 81
  150.      WindowChangeCursor() ............................................ 81
  151.      WindowMoveCursor() .............................................. 82
  152.      WindowGetCursorShape() .......................................... 83
  153.      WindowGetCursorPosition() ....................................... 84
  154.  
  155.  
  156.   GETTING INPUT FROM WINDOWS ......................................... 86
  157.      Input Manager ................................................... 86
  158.      Regular Expressions ............................................. 86
  159.      Editing Input ................................................... 90
  160.      Last Key Value .................................................. 91
  161.      Default Cursor Types and Editing Mode ........................... 92
  162.      Editing using a character mask .................................. 93
  163.      Editing Functions ............................................... 93
  164.         WindowGetString() ............................................ 93
  165.         WindowGetStringAttr() ........................................ 96
  166.         WindowGetMaskString() ........................................ 97
  167.         WindowGetMaskStringAttr() .................................... 98
  168.         Getting Passwords ............................................ 99
  169.            WindowGetPassword() ....................................... 99
  170.            WindowGetPasswordAttr() ................................... 100
  171.            WindowGetMaskPassword() ................................... 101
  172.            WindowGetMaskPasswordAttr() ............................... 101
  173.  
  174.  
  175.  Page iii                   The C Window Library                    Page iii
  176.                        T A B L E   O F   C O N T E N T S
  177.      UNDEFINED KEYSTROKE PROCESSING .................................. 104
  178.         The undef_fkey_func and undef_akey_func function pointers .... 104
  179.         Specifying when to call an undefined key function in a
  180.            Regular Expression ........................................ 105
  181.            Return Values To The Input Manager ........................ 105
  182.  
  183.  
  184.      INPUT OPTIONS ................................................... 108
  185.         CHECKREGEXP and the reg_exp_error_func function pointer ...... 109
  186.      THE num_chars_entered_func FUNCTION POINTER ..................... 112
  187.  
  188.  
  189.      OTHER INPUT RELATED FUNCTIONS ................................... 113
  190.         TranslateStringToMaskString() ................................ 113
  191.         TranslateMaskStringToString() ................................ 115
  192.  
  193.  
  194.   VIRTUAL WINDOWS .................................................... 116
  195.      Using Windows as Viewports ...................................... 116
  196.      Attributed and Non-Attributed Virtual Windows ................... 116
  197.      Virtual Window's Logical Cursor ................................. 117
  198.  
  199.  
  200.      CREATING VIRTUAL WINDOWS ........................................ 118
  201.         VirtualInitialize() .......................................... 118
  202.  
  203.  
  204.      ASSIGNING VIEWPORTS AND CLOSING VIEWPORTS ....................... 120
  205.         WindowAssignToVirtual() ...................................... 120
  206.         Out of bounds Coordinates .................................... 121
  207.         WindowCloseViewport() ........................................ 122
  208.  
  209.  
  210.      WRITING TEXT TO VIRTUAL WINDOWS ................................. 124
  211.         Null Terminated String Functions ............................. 124
  212.            VirtualWriteString() ...................................... 124
  213.            VirtualWriteStringAttr() .................................. 125
  214.            VirtualWriteCenterString() ................................ 126
  215.            VirtualWriteCenterStringAttr() ............................ 127
  216.            VirtualWriteStringCC() .................................... 128
  217.            VirtualWriteStringCCAttr() ................................ 129
  218.            VirtualWriteStringRJ() .................................... 130
  219.            VirtualWriteStringRJAttr() ................................ 131
  220.         Length Controlled Functions .................................. 132
  221.            VirtualWriteCharacters() .................................. 132
  222.            VirtualWriteAttributes() .................................. 133
  223.            VirtualWriteCharAndAttr() ................................. 134
  224.            VirtualWriteRepeatAttribute() ............................. 135
  225.            VirtualWriteRepeatCharacter() ............................. 136
  226.         Formatted Write Functions .................................... 137
  227.            Format String ............................................. 137
  228.            Where Output is Placed .................................... 137
  229.            VirtualSetWrap() .......................................... 137
  230.  
  231.  Page iv                    The C Window Library                    Page iv
  232.                        T A B L E   O F   C O N T E N T S
  233.            VirtualPrintf() ........................................... 138
  234.            VirtualPrintfAttr() ....................................... 139
  235.  
  236.  
  237.      READING CHARACTERS AND ATTRIBUTES FROM VIRTUAL WINDOWS .......... 140
  238.         VirtualReadCharacters() ...................................... 140
  239.         VirtualReadAttributes() ...................................... 141
  240.  
  241.         VirtualReadCharAndAttr() ..................................... 142
  242.  
  243.  
  244.      REPOSITIONING THE VIEWPORT ...................................... 144
  245.         WindowPositionViewport() ..................................... 144
  246.  
  247.  
  248.      SCROLLING THE VIEWPORTS ......................................... 148
  249.         WindowScrollVirtual() ........................................ 148
  250.  
  251.  
  252.      WRITING VIRTUAL WINDOW CONTENTS TO A FILE ....................... 151
  253.         VirtualWriteTextToFile() ..................................... 151
  254.  
  255.  
  256.      MOVING THE LOGICAL CURSOR ....................................... 153
  257.         VirtualMoveCursor() .......................................... 153
  258.         VirtualGetCursorPosition() ................................... 153
  259.  
  260.  
  261.      CLEARING VIRTUAL WINDOWS ........................................ 155
  262.         VirtualClear() ............................................... 155
  263.         VirtualClearAttr() ........................................... 156
  264.         VirtualClearRegion() ......................................... 156
  265.         VirtualClearRegionAttr() ..................................... 157
  266.  
  267.  
  268.      FREEZING VIEWPORTS .............................................. 159
  269.         WindowFreeze() ............................................... 159
  270.  
  271.  
  272.      DISPOSING OF VIRTUAL WINDOWS .................................... 161
  273.         VirtualFree() ................................................ 161
  274.  
  275.  
  276.   INTRODUCTION TO MENU SYSTEM ........................................ 163
  277.      Menu Manager .................................................... 163
  278.      Necessary "include" files ....................................... 163
  279.  
  280.  
  281.      POP-UP MENUS .................................................... 164
  282.         Description .................................................. 164
  283.         Windows and Virtual Windows .................................. 164
  284.  
  285.  
  286.  
  287.  Page v                     The C Window Library                    Page v
  288.                        T A B L E   O F   C O N T E N T S
  289.      CREATING POP-UP MENUS ........................................... 165
  290.         The POPUP_MENU_ENTRY structure ............................... 165
  291.            Defining Hotkeys .......................................... 166
  292.            Assigning the function to perform ......................... 167
  293.         Coloring Popup Menus ......................................... 167
  294.         PopupCreateMenu() function ................................... 168
  295.            Popup Menu Options ........................................ 170
  296.            Default Popup Window and Creating Your own Windows ........ 172
  297.            Default Virtual Window and ................................ 173
  298.  
  299.            Creating Your own Virtual Windows ......................... 173
  300.            Accessing Popup Windows and Virtual Windows ............... 173
  301.            Warnings .................................................. 174
  302.            Return Values for PopupCreateMenu() ....................... 174
  303.  
  304.  
  305.      SELECTING FROM POPUP MENUS ...................................... 176
  306.         PopupSelectMenu() function ................................... 176
  307.            Values passed to menu function ............................ 178
  308.            Values returned to menu manager ........................... 178
  309.            Return Values for PopupSelectMenu() ....................... 179
  310.  
  311.  
  312.      SETTING OPTIONS IN POPUP MENUS .................................. 180
  313.         The PopupSetOptions() function ............................... 180
  314.            Setting Multiple Options .................................. 181
  315.            Setting the PopupSetConfirmFunction() ..................... 181
  316.            Return Values for PopupSetOptions() function .............. 182
  317.  
  318.  
  319.      MAKING MENU ENTRIES AVAILABLE AND UNAVAILABLE ................... 183
  320.         PopupMakeEntryAvailable() and ................................ 183
  321.         PopupMakeEntryUnavailable() functions ........................ 183
  322.            POPUPOVERRIDE option ...................................... 183
  323.         Return Values for PopupMakeEntryAvaialble() and .............. 183
  324.         PopupMakeEntryUnavailable() functions ........................ 183
  325.  
  326.  
  327.      CHANGING THE MENU ENTRY STRINGS ................................. 185
  328.         PopupChangeEntryString() function ............................ 185
  329.         Return Values for PopupChangeEntryString() function .......... 185
  330.  
  331.  
  332.      REDEFINING MENU KEYS ............................................ 186
  333.         Setting Global Key Definitions and ........................... 186
  334.         the popup_key_definition Array ............................... 186
  335.         Setting Local Key Definitions ................................ 186
  336.            PopupAssignKeys() function ................................ 187
  337.            Return Values for PopupAssignKeys() function .............. 187
  338.  
  339.  
  340.  
  341.  
  342.  
  343.  Page vi                    The C Window Library                    Page vi
  344.                        T A B L E   O F   C O N T E N T S
  345.      PROCESSING UNDEFINED KEYS ....................................... 188
  346.         The popup_undef_key function pointer ......................... 188
  347.            Values returned to menu manager ........................... 188
  348.  
  349.  
  350.      PRE-INPUT FUNCTION .............................................. 191
  351.         Setting the global_popup_prefunc function pointer ............ 191
  352.  
  353.  
  354.      DISPOSING OF POPUP MENUS ........................................ 193
  355.         PopupMenuFree() .............................................. 193
  356.         Return Values for PopupMenuFree() ............................ 193
  357.  
  358.  
  359.   BAR MENUS .......................................................... 194
  360.      Description ..................................................... 194
  361.      Windows and Virtual Windows ..................................... 194
  362.      CREATING BAR MENUS .............................................. 195
  363.         The BAR_MENU_ENTRY structure ................................. 195
  364.            Defining Hotkeys .......................................... 196
  365.            Assigning the function to perform ......................... 197
  366.         Coloring Bar Menus ........................................... 197
  367.         BarCreateMenu() function ..................................... 198
  368.            Bar Menu Options .......................................... 200
  369.            Default Bar Menu Window and Creating Your own Windows ..... 201
  370.            Accessing bar menu windows ................................ 202
  371.            Warnings .................................................. 203
  372.            Return Values for BarCreateMenu() ......................... 203
  373.  
  374.  
  375.      SELECTING FROM BAR MENUS ........................................ 205
  376.         BarSelectMenu() function ..................................... 205
  377.            Values passed to menu function ............................ 206
  378.            Values returned to menu manager ........................... 207
  379.            Return Values for BarMenuSelect() ......................... 207
  380.  
  381.  
  382.      SETTING OPTIONS IN BAR MENUS .................................... 208
  383.         The BarSetOptions() function ................................. 208
  384.            Setting Multiple Options .................................. 209
  385.            Setting the BarSetConfirmFunction() ....................... 209
  386.            Return Values for BarSetOptions() function ................ 210
  387.  
  388.  
  389.      MAKING ENTRIES AVAILABLE AND UNAVAILABLE ........................ 211
  390.         BarMakeEntryAvailable() and .................................. 211
  391.         BarMakeEntryUnavailable() functions .......................... 211
  392.            BAROVERRIDE option ........................................ 211
  393.         Return Values for BarMakeEntryAvaialble() and ................ 211
  394.         BarMakeEntryUnavailable() functions .......................... 211
  395.  
  396.  
  397.  
  398.  Page vii                   The C Window Library                    Page vii
  399.                        T A B L E   O F   C O N T E N T S
  400.      CHANGING THE MENU OPTIONS STRING ................................ 212
  401.         BarChangeEntryString() function .............................. 212
  402.            Return Values for BarChangeEntryString() function ......... 212
  403.  
  404.  
  405.      REDEFINING THE MENU KEYS ........................................ 213
  406.         Setting Global Key Definitions and ........................... 213
  407.         the bar_key_definition Array ................................. 213
  408.         Setting Local Key Definitions ................................ 213
  409.            BarAssignKeys() function .................................. 213
  410.            Return Values for BarAssignKeys() function ................ 214
  411.  
  412.  
  413.      PROCESSING UNDEFINED KEYS ....................................... 215
  414.         The bar_undef_key function pointer ........................... 215
  415.            Values returned to menu manager ........................... 215
  416.  
  417.  
  418.      PRE-INPUT FUNCTION .............................................. 218
  419.         Setting the global_bar_prefunc function pointer .............. 218
  420.  
  421.  
  422.      DISPOSING OF BAR MENUS .......................................... 220
  423.         BarMenuFree() function ....................................... 220
  424.         Return Values for BarMenuFree() .............................. 220
  425.  
  426.  
  427.   PULLDOWN MENUS ..................................................... 221
  428.      Description ..................................................... 221
  429.      Bar Menu and Popup Menu levels .................................. 221
  430.  
  431.  
  432.      CREATING PULLDOWN MENUS ......................................... 222
  433.         The PulldownCreateMenu() function ............................ 223
  434.            Automatic Adjustment of Popup Windows ..................... 225
  435.         Return values for PulldownCreateMenu() ....................... 227
  436.  
  437.  
  438.      SELECTING FROM PULLDOWN MENUS ................................... 228
  439.         The PulldownSelectMenu() function ............................ 228
  440.            Immediate Mode ............................................ 228
  441.            Values passed to the selected menu function ............... 229
  442.            Values returned to the menu manager ....................... 229
  443.            Return Values for PulldownSelectMenu() .................... 229
  444.  
  445.  
  446.      REDEFINING KEY DEFINITIONS ...................................... 230
  447.  
  448.  
  449.         REDEFINING KEY DEFINITIONS FOR POPUP MENUS ................... 231
  450.            Setting Popup Menu Global Key Definitions ................. 231
  451.            Setting Popup Menu Local Definitions ...................... 231
  452.  
  453.  
  454.  Page viii                  The C Window Library                    Page viii
  455.                        T A B L E   O F   C O N T E N T S
  456.         REDEFINING KEY DEFINITIONS FOR THE BAR MENU .................. 233
  457.            Setting bar menu global key definitions ................... 233
  458.            Setting Bar Menu Local definitions ........................ 233
  459.  
  460.  
  461.      PROCESSING UNDEFINED POPUP MENU KEYS ............................ 234
  462.  
  463.  
  464.      PROCESSING UNDEFINED BAR MENU KEYS .............................. 235
  465.  
  466.  
  467.  
  468.  
  469.      DISPOSING OF PULLDOWN MENUS ..................................... 236
  470.         The PulldownMenuFree() function .............................. 236
  471.         The PulldownMenuFreeAll() function ........................... 236
  472.  
  473.  
  474.      SUMMARY OF PULLDOWN MENUS ....................................... 237
  475.  
  476.  
  477.      EXAMPLE OF PULLDOWN MENU SYSTEM ................................. 238
  478.  
  479.  
  480.   MISCELLANEOUS FUNCTIONS ............................................ 243
  481.  
  482.  
  483.      SETTING AND CHECKING VIDEO PAGES ................................ 243
  484.         CheckVideoPage() ............................................. 243
  485.         SetActiveVideoPage() function ................................ 244
  486.         SetVisibleVideoPage() function ............................... 245
  487.  
  488.  
  489.      GENERAL STRING WRITING FUNCTIONS ................................ 247
  490.         VideoWriteString() ........................................... 247
  491.         VideoWriteStringAttr() ....................................... 248
  492.         VideoWriteAttributes() ....................................... 248
  493.         VideoWriteCenterString() ..................................... 249
  494.         VideoWriteCenterStringAttr() ................................. 250
  495.         VideoWriteCharAndAttr() ...................................... 250
  496.         VideoWriteStringCC() ......................................... 251
  497.         VideoWriteStringCCAttr() ..................................... 252
  498.         VideoWriteStringRJ() ......................................... 252
  499.         VideoWriteStringRJAttr() ..................................... 253
  500.         VideoPrintf() ................................................ 254
  501.         VideoPrintfAttr() ............................................ 254
  502.  
  503.  
  504.      READING CHARACTERS AND ATTRIBUTES FROM THE SCREEN ............... 255
  505.         VideoReadCharacters() ........................................ 255
  506.         VideoReadAttributes() ........................................ 255
  507.         VideoReadCharAndAttr() ....................................... 256
  508.  
  509.  
  510.  Page ix                    The C Window Library                    Page ix
  511.                        T A B L E   O F   C O N T E N T S
  512.      DRAWING BOXES ................................................... 257
  513.         VideoDrawBox() ............................................... 257
  514.         VideoDrawBoxAttr() ........................................... 257
  515.  
  516.  
  517.      SAVING AND RESTORING SCREEN IMAGES .............................. 259
  518.         VideoSave() .................................................. 259
  519.         VideoMove() .................................................. 260
  520.         VideoRestore() ............................................... 260
  521.         VideoFree() .................................................. 261
  522.  
  523.  
  524.  
  525.      CLEARING SCREENS ................................................ 262
  526.         ClearScreen() ................................................ 262
  527.         ClearRegion() ................................................ 262
  528.  
  529.  
  530.      SCROLLING SCREENS ............................................... 264
  531.         ScrollScreenUp() ............................................. 264
  532.         ScrollScreenDown() ........................................... 264
  533.  
  534.  
  535.      CHANGING THE VIDEO MODE ......................................... 266
  536.         SetVideoMode() ............................................... 266
  537.  
  538.  
  539.      CHANGING THE NUMBER OF ROWS AND COLUMNS ON THE SCREEN ........... 267
  540.         Changing rows ................................................ 267
  541.            AdjustScreenInfo() ........................................ 267
  542.            AdjustGlobalData() ........................................ 268
  543.            SetVideoRows() ............................................ 268
  544.         Changing columns ............................................. 271
  545.            40 column and 80 column modes ............................. 271
  546.            Modes higher than 80 columns .............................. 271
  547.  
  548.  
  549.      CURSOR MANIPULATION ............................................. 273
  550.         MoveCursor() ................................................. 273
  551.         ChangeCursor() ............................................... 273
  552.         GetCursorShape() ............................................. 274
  553.         GetCursorPosition() .......................................... 274
  554.         HideCursor() ................................................. 275
  555.         BlockCursor() ................................................ 275
  556.         ThinCursor() ................................................. 275
  557.  
  558.  
  559.      GETTING VIDEO INFORMATION ....................................... 277
  560.         VIDEO_CONFIG structure ....................................... 277
  561.         GetVideoBiosInfo() ........................................... 277
  562.  
  563.  
  564.  
  565.  
  566.  Page x                     The C Window Library                    Page x
  567.                        T A B L E   O F   C O N T E N T S
  568.      TIMED DELAYS .................................................... 279
  569.         delay() ...................................................... 279
  570.  
  571.  
  572.      SOUND FUNCTIONS ................................................. 280
  573.         sound() and nosound() ........................................ 280
  574.         MakeSound() .................................................. 280
  575.  
  576.  
  577.      ERROR HANDLING .................................................. 282
  578.         The window_error_func function pointer ....................... 282
  579.  
  580.  
  581.      USING A MOUSE WITH THE C WINDOW LIBRARY ......................... 284
  582.         Installing the Mouse Library ................................. 284
  583.         Include Files ................................................ 284
  584.         Initializing the Mouse with MouseInitializeSystem() .......... 284
  585.         Turning off the mouse with MouseRestoreSystem() .............. 285
  586.         Using a mouse with popup menus ............................... 286
  587.         Using a mouse with bar menus ................................. 288
  588.         Using a mouse with pulldown menus ............................ 289
  589.         Changing the mouse defaults .................................. 294
  590.  
  591.  
  592.      WINDOW AND VIRTUAL WINDOW MACROS ................................ 295
  593.  
  594.  
  595.      MENU MACROS ..................................................... 298
  596.         Popup Menu Macros ............................................ 298
  597.         Bar Menu Macros .............................................. 299
  598.         Pulldown Menu Macros ......................................... 300
  599.  
  600.  
  601.      VIDEO MACROS .................................................... 301
  602.  
  603.  
  604.      BOX MACROS ...................................................... 304
  605.  
  606.  
  607.      EXPLOSION MACROS ................................................ 305
  608.  
  609.  
  610.      KEYBOARD MACROS ................................................. 306
  611.        Keyboard Idle Function ........................................ 307
  612.        Keyboard Intercept Function ................................... 308
  613.  
  614.  
  615.      CURSOR MACROS ................................................... 309
  616.  
  617.  
  618.   IMPORTANT GLOBAL VARIABLES ......................................... 310
  619.  
  620.  
  621.  
  622.  Page xi                    The C Window Library                    Page xi
  623.  
  624.                                  INTRODUCTION
  625.                                  ------------
  626.  
  627.   Defining Windows
  628.   ----------------
  629.  
  630.   A window is an area of the screen that is separate and independent from the
  631.   other areas of the screen.  With windows, you can scroll, write text, delete
  632.   text, etc. in a defined section of the screen.  An example of windows in
  633.   application programs are the resident memory utilities that pop up on the
  634.   screen when invoked, and restore the text to its original state when the
  635.   resident application is terminated.  Sidekick is a good example of what you
  636.   can do with windows.  As a matter of fact, most professional programs use
  637.   windows in some manner.  Some applications use windows to make pulldown menus
  638.   i.e. the integrated environment in the Turbo languages and in Microsoft Quick
  639.   C's integrated environment.  Other applications such as text editors and word
  640.   processors use windows to display and edit a files contents.  With The C
  641.   Window Library, you can create professional looking application program easily
  642.   and without worrying about the tricky details of window management.  At your
  643.   disposal are tools that can help you create pull-down menus, popup menus, bar
  644.   menus, and just fast output.
  645.  
  646.  
  647.   Properties of Windows
  648.   ---------------------
  649.  
  650.   Windows should have the following properties:
  651.     - more than one window can be displayed on the screen simultaneously.
  652.     - windows are allowed to overlap without disturbing the contents of
  653.       the windows underneath.
  654.     - a window that is under a pile of windows can be brought to the top.
  655.     - a window that is under a pile of windows can be written to without
  656.       interfering with other windows.
  657.     - windows can be disposed of when not needed, and erased from the screen.
  658.       When erased, the contents of the screen underneath the window is restored.
  659.     - windows can be written to at any time.
  660.     - the window application should automatically detect the type of video
  661.       hardware used.
  662.     - the window functions should return an error if something goes wrong.
  663.  
  664.  
  665.   Writing to Overlapping Windows
  666.   ------------------------------
  667.  
  668.   With The C Window Library, if a window does overlap another window, this
  669.   overlap will be displayed on the physical screen.  The C Window Library
  670.   allows you to direct output to any window at any time.  When output is
  671.   written to a window, the window contents are updated in memory, but only the
  672.   visible portions of the window will be updated on the screen.
  673.  
  674.  
  675.  
  676.  
  677.  
  678.  Page 1                     The C Window Library                    Page 1
  679.  
  680.  
  681.   Window Ranks
  682.   ------------
  683.  
  684.   The rank order of the windows on the screen will determine which window has
  685.   priority of the screen.
  686.  
  687.   Windows with lower rank numbers overlap windows with higher rank numbers.  The
  688.   lowest rank number is 1, and the highest is 254.  If a new window is opened
  689.   with the same rank number as another previously opened window, the new window
  690.   takes over the rank position, and the previous window's rank is increased
  691.   by 1.   If there is a window with the same rank as the previous window's new
  692.   rank, its rank is increased by 1 etc.  When a window is closed, all windows
  693.   with a higher rank number are decreased by 1.
  694.  
  695.  
  696.  
  697.   Detection of Video Hardware
  698.   ---------------------------
  699.  
  700.   With The C Window Library, automatic detection of the type of video hardware
  701.   is necessary.  Since The C Window Library can write directly to screen memory,
  702.   the starting memory address of screen memory must be known.  Depending on the
  703.   video adapter, the starting address of screen memory is different.  For
  704.   monochrome systems, the starting address is different from a color system.
  705.   If the window routines think that they are writing to a color system instead
  706.   of a monochrome system, crazy things will probably happen.  For most
  707.   adapters, The C Window Library will detect them and assign the starting
  708.   address of screen memory to a global variable, so there is no need to specify
  709.   the starting address yourself.
  710.  
  711.  
  712.  
  713.   Window Coordinates
  714.   ------------------
  715.  
  716.   A position on the screen can be specified as a pair of numbers.  These numbers
  717.   will denote the row and column of the desired position.  Rows and columns are
  718.   numbered from 1 to the maximum row or column number.  The upper left hand
  719.   corner of the screen would be at row 1, column 1.  For simplicity, row y,
  720.   column x will be abbreviated as (y,x).  The position (1,1) is called  the home
  721.   position.
  722.  
  723.   However, when specifying a position in a window, this position is numbered
  724.   relative to the window itself.  No matter where a window resides on the
  725.   screen, the upper left position of the window is (1,1), the second row of the
  726.   window is row 2, the fourth column is column 4, etc.  The window coordinates
  727.   are called window relative coordinates.  There are some window functions that
  728.   require you to enter physical screen (absolute) coordinates, but for most
  729.   functions, a window relative position would be needed.  For example:
  730.  
  731.  
  732.  
  733.  
  734.  Page 2                     The C Window Library                    Page 2
  735.  
  736.   -------------------------------------------------------------------
  737.   |(1,1)                                                      (80,1)|
  738.   |                                                                 |
  739.   |                Valid Absolute Screen Coordinates                |
  740.   |                      For 80 x 25 Screen                         |
  741.   |                                                                 |
  742.   |     This window opened at absolute (12,15)                      |
  743.   |            |                                                    |
  744.   |            v                                                    |
  745.   |            -----------------------                              |
  746.   |            |(1,1)          (1,30)|                              |
  747.   |            |                     |                              |
  748.   |            |                     |                              |
  749.   |            |(14,1)        (14,30)|                              |
  750.   |            -----------------------                              |
  751.   |(1,25)                                                    (80,25)|
  752.   -------------------------------------------------------------------
  753.  
  754.  
  755.  
  756.   Video Attributes
  757.   ----------------
  758.  
  759.   With The C Window Library, a window can have an assortment of colors for text
  760.   and background.  Each character that is displayed on the screen has its
  761.   corresponding attribute byte.  The attribute byte is an 8-bit quantity that
  762.   specifies a character's color, intensity, and blink status.  The format of the
  763.   attribute byte is as follows:
  764.  
  765.                       7  6  5  4  3  2  1  0
  766.                     --------------------------
  767.                     |B | bground |I|fground  |
  768.                     |__|_________|_|_________|
  769.  
  770.  
  771.   The B is the blink bit and the I is the intensity bit.  Bits 0 thru 2
  772.   is a color code for the foreground (text) color.  Bits 4 thru 6 determine
  773.   the color code for the background (screen) color.
  774.  
  775.   If the blink bit is 1, then the character will blink.  If the intensity bit is
  776.   on, the character will appear brighter than usual.  Some monitors cannot
  777.   display high intensity characters, so the intensity bit may not change the
  778.   characters brightness at all.
  779.  
  780.        Here is a list of color values along with the color they represent:
  781.  
  782.  
  783.      Value      Color                 Value        Color
  784.  
  785.        0        Black                  8          Gray
  786.        1        Blue                   9          Light blue
  787.        2        Green                 10          Light green
  788.  
  789.  
  790.  Page 3                     The C Window Library                    Page 3
  791.  
  792.        3        Cyan                  11          Light cyan
  793.        4        Red                   12          Light red
  794.        5        Magenta               13          Light magenta
  795.        6        Brown                 14          Yellow
  796.        7        White                 15          Intense white
  797.  
  798.   If the video system is a monochrome system, the color values specified above
  799.   will give unpredictable results if not used carefully.  Monochrome systems
  800.   also have an underline mode, that color systems (unless if you program the
  801.   EGA or VGA adapters) cannot display.  Upcoming is a list of color values
  802.   that should work on monochrome systems along with the type of display that
  803.   will be produced:
  804.  
  805.  
  806.      Display          Background      Foreground
  807.  
  808.      No display          0                 0
  809.      Underline           0                 1
  810.      Normal Video        0                 7
  811.      Reverse Video       7                 0
  812.  
  813.   When programming a monochrome system, you can change the values of the colors
  814.   not supported to black and white combinations supported on the monochrome
  815.   system.  For example, you can change the light green color's value from 10 to
  816.   7.  Now if light green is selected as a foreground color and the background
  817.   color is black, you will have a normal video display on a monochrome system.
  818.  
  819.  
  820.  
  821.   Direct Screen Writes and BIOS Screen Updates
  822.   --------------------------------------------
  823.  
  824.   By default, The C Window Library writes directly to screen memory.  This
  825.   results in very fast screen output.  If you have ever wondered how commercial
  826.   programs can display output so rapidly on the screen, direct screen writing
  827.   is the major reason.  The disadvantage of writing directly to the screen is
  828.   that it is ill- behaved with programs like Microsoft Windows or Quarterdeck's
  829.   DesQView (although DesQView386 running on an 80386 machine is well behaved
  830.   with direct screen writes).  Also on some color systems, the screen output is
  831.   so fast that the video display produces "snow" on the screen.  However, The C
  832.   Window Library will automatically detect whether "snow" should be checked
  833.   when writing directly to the screen.  The old IBM Color Graphics Adapters
  834.   suffer from this problem, but most other adapters including monochrome,
  835.   Hercules, EGA, VGA, and newer CGA's do not suffer from this problem.  When
  836.   checking for snow, the screen writes are not as fast as when there is no snow
  837.   checking, but it is fast enough.
  838.  
  839.   The other method of updating the screen is by making a call to the video
  840.   functions contained in the ROM BIOS.  BIOS stands for Basic Input Output
  841.   System.  The BIOS provides routines that are needed for the operation of the
  842.   computer.  Some of these routines are video functions needed to write
  843.   characters and attributes, move the cursor, and scroll portions of the
  844.   screen.  Using the BIOS instead of writing directly to screen memory results
  845.  
  846.  Page 4                     The C Window Library                    Page 4
  847.  
  848.   in much slower screen updates, but will be compatible with programs like
  849.   Microsoft Windows and DesQView.
  850.  
  851.   With The C Window Library, you are allowed to use either method.
  852.  
  853.  
  854.  
  855.  
  856.   Video Paging
  857.   ------------
  858.  
  859.   Since most video display adapters have enough memory to store more than one
  860.   screen of characters,  these video adapters will support multiple video pages.
  861.   With multiple video pages, you can write to a hidden video page and then
  862.   display the entire video page instantaneously. The only adapter that does
  863.   not support video paging is the Monochrome Display Adapter (MDA).  All
  864.   CGA's, EGA's and VGA's support multiple video pages.   The maximum number
  865.   of pages a card will support is determined by the amount of RAM included in
  866.   the video board, and the maximum number of characters that can be displayed
  867.   on each page.  A list of the maximum number of video pages in each mode for
  868.   each card is as follows:
  869.  
  870.  
  871.  
  872.         BIOS        Mode                               Max. #
  873.         Mode #      Type           Adapter            of pages
  874.         ----        ----           -------            --------
  875.         0,1         Text        CGA, EGA, VGA             8
  876.         2,3         Text        CGA,                      4
  877.                                 EGA, VGA                  8
  878.         7           Text        MDA, Hercules             1
  879.                                 EGA, VGA                  8
  880.  
  881.   With The C Window Library, the video page displayed on the screen is called
  882.   the visible page.  When creating a window, its page number is recorded.
  883.   When updating windows, the video page number where the window resides is
  884.   used to direct the output to the appropriate video page.  There are also
  885.   functions in The C Window Library that allow you to switch video pages.
  886.   With these routines, you can create very sophisticated user interfaces.
  887.   If you are using a clone Hercules Monochrome adapter, you may have access to
  888.   more than one video page.  The original Hercules card has only one page of
  889.   text memory.  The problem of accessing the other pages in the clone cards is
  890.   that there is no universal way to determine how many pages that the card
  891.   has.  If you are writing an application that targets a specific Hercules
  892.   clone card, and you want to take advantage of the multiple pages, you can
  893.   modify a global variable that contains the maximum number of available video
  894.   pages, as well as the array that contains the segment:offset of each video
  895.   page.  Make sure you have the full documentation for the card, or know
  896.   off-hand the number of pages and their addresses.
  897.  
  898.  
  899.  
  900.  
  901.  
  902.  Page 5                     The C Window Library                    Page 5
  903.  
  904.   Error Codes
  905.   -----------
  906.  
  907.   With most of The C Window Library functions, window_error_code, which is a
  908.   global integer variable is set to an error number when a function cannot be
  909.   completed.  Throughout this documentation, you are to assume that
  910.   window_error_code is set to any error condition that is documented for
  911.   each function.  The window_error_code variable IS NOT reset when a function
  912.   has been completed successfully.  A list of error codes is as follows:
  913.  
  914.  
  915.      Error Constant       Error Code           Definition
  916.      --------------       ----------           ----------
  917.  
  918.     NO_HEAP_MEM               -1          Not enough memory to allocate from
  919.                                           the heap.
  920.  
  921.     BAD_DISPLAY_PAGE          -2          Video Display page is invalid.
  922.  
  923.     INVALID_VIDEO_MODE        -3          Invalid video mode.
  924.  
  925.     INVALID_ROWS              -4          Invalid number of screen rows
  926.                                           specified.
  927.  
  928.     BAD_WINDOW                -100        Window does not exist.
  929.  
  930.     BAD_WINDOW_SIZE           -101        Window dimensions are invalid.
  931.  
  932.     WINDOW_NOT_OPEN           -102        Window not open for read/write.
  933.  
  934.     WINDOW_BOUND              -103        Coordinates specified for window are
  935.                                           out of bounds.
  936.  
  937.     MAX_WINDOW                -104        Maximum number of windows defined.
  938.  
  939.  
  940.     WINDOW_INV_PARAM          -105        An invalid parameter was encountered
  941.                                           in the function call.
  942.  
  943.     NO_INPUT_CHARS            -106        Trying to input a field of 0
  944.                                           characters.
  945.  
  946.     BAD_V_WINDOW              -200        The virtual window does not exist.
  947.  
  948.     END_V_WINDOW              -201        Internally used by The C Window
  949.                                           Library.
  950.  
  951.     V_WINDOW_BOUND            -202        Coordinates specified for virtual
  952.                                           window are out of bounds.
  953.  
  954.     MAX_V_WINDOW              -203        Maximum number of virtual windows
  955.                                           defined.
  956.  
  957.  
  958.  Page 6                     The C Window Library                    Page 6
  959.  
  960.     NO_ATTRIB                 -204        Virtual window does not have
  961.                                           attributes.
  962.  
  963.     FILE_NO_EXIST             -300        File does not exist.
  964.  
  965.     FILE_CANT_CLOSE           -301        Cannot close file.
  966.  
  967.     FILE_CANT_OPEN            -302        Cannot open file.
  968.  
  969.     MENU_ENTRY_INVALID        -400        An invalid menu entry was specified.
  970.  
  971.  
  972.  
  973.  
  974.  
  975.  
  976.   Window Manager
  977.   --------------
  978.  
  979.   The window manager is the code in The C Window Library that handles window
  980.   initialization, movement, coloring, and other functions that control window
  981.   management.
  982.  
  983.  
  984.  
  985.  
  986.  
  987.  
  988.  
  989.  
  990.  
  991.  
  992.  
  993.  
  994.  
  995.  
  996.  
  997.  
  998.  
  999.  
  1000.  
  1001.  
  1002.  
  1003.  
  1004.  
  1005.  
  1006.  
  1007.  
  1008.  
  1009.  
  1010.  
  1011.  
  1012.  
  1013.  
  1014.  Page 7                     The C Window Library                    Page 7
  1015.  
  1016.                      MANDATORY FUNCTIONS AND HEADER FILES
  1017.                      ------------------------------------
  1018.  
  1019.   The only mandatory function is WindowInitializeSystem(), explained below.
  1020.   The window.h header file must be included in any module that will call
  1021.   functions included in The C Window Library.
  1022.  
  1023.  
  1024.   WindowInitializeSystem()
  1025.   ------------------------
  1026.  
  1027.   This function MUST be called before any other function defined in The C
  1028.   Window Library.  This function also sets global variables, so it is also
  1029.   mandatory to call WindowInitializeSystem() before accessing any global
  1030.   variables defined by The C Window Library.
  1031.  
  1032.   WindowInitializeSystem() detects the type of video display used, the number
  1033.   of rows and columns that the screen currently displays, and initializes data
  1034.   structures and global variables.
  1035.  
  1036.   Example:
  1037.  
  1038.       #include "window.h"
  1039.  
  1040.       main()
  1041.       {
  1042.         WindowInitializeSystem();   /* Initialization function */
  1043.         /* Now it is safe to use C Window Library functions and global
  1044.            variables */
  1045.       }
  1046.  
  1047.   There is no return value for WindowInitializeSystem().
  1048.  
  1049.  
  1050.  
  1051.  
  1052.  
  1053.  
  1054.  
  1055.  
  1056.  
  1057.  
  1058.  
  1059.  
  1060.  
  1061.  
  1062.  
  1063.  
  1064.  
  1065.  
  1066.  
  1067.  
  1068.  
  1069.  
  1070.  Page 8                     The C Window Library                    Page 8
  1071.  
  1072.                                CREATING WINDOWS
  1073.                                ----------------
  1074.  
  1075.   We will now look how a window is created by defining a WINDOW, WPOINTER, and
  1076.   using the WindowSaveInitial() and WindowInitialize() function.
  1077.  
  1078.  
  1079.  
  1080.   The WINDOW structure and WPOINTER structure pointer
  1081.   ---------------------------------------------------
  1082.  
  1083.   When a window is created, the upper left hand column and row, the width,
  1084.   height, etc. must be recorded.  It would be very tedious if for every
  1085.   function call that acts on these windows we have to specify width, height,
  1086.   upper left hand row, etc. as function parameters.  The C Window Library
  1087.   conveniently has a structure called WINDOW, and its corresponding pointer
  1088.   called a WPOINTER to alleviate these problems.
  1089.  
  1090.   When a window is created, its characteristics are stored in a WINDOW
  1091.   structure, and most functions require that a pointer to this structure be
  1092.   passed.  This pointer is called a WPOINTER.  By only referring to the
  1093.   WPOINTER, argument lists to functions become much shorter.
  1094.  
  1095.  
  1096.  
  1097.  
  1098.   WindowSaveInitial()
  1099.   -------------------
  1100.  
  1101.   The WindowSaveInitial() function saves the base screen as a window.  This
  1102.   MUST be called prior to creating any windows.  Here is a prototype:
  1103.  
  1104.        int WindowSaveInitial(int page)
  1105.  
  1106.   The page argument is the video page of the base screen to save.  If you are
  1107.   creating windows that will be manipulated on video page 0, you must call
  1108.   WindowSaveInitial() with 0 as the argument:
  1109.  
  1110.        #include "window.h"
  1111.  
  1112.        main()
  1113.        {
  1114.          WindowInitializeSystem();  /* Initialize global variables */
  1115.          WindowSaveInitial(0);      /* Save video page 0's base screen */
  1116.        }
  1117.  
  1118.   In most applications, the initial screen page is page 0.  However, it is
  1119.   safer to use the global variable active_video_page (explained in the
  1120.   IMPORTANT GLOBAL VARIABLES section) to determine the page.  If you are
  1121.   changing video pages in an application, and the new page has not been
  1122.   accessed, you should call WindowSaveInitial() for that page.  It is important
  1123.   to save the base screen before writing windows on the screen.  If the base is
  1124.   not saved, the window manager will not update the
  1125.  
  1126.  Page 9                     The C Window Library                    Page 9
  1127.  
  1128.   screen properly when moving windows, hiding windows, etc.  This function must
  1129.   be called only once in an application for each screen page desired.
  1130.  
  1131.   If there is no error, WindowSaveInitial() returns NO_ERROR.
  1132.   If there is an error, WindowSaveInitial() returns the following values:
  1133.  
  1134.     BAD_DISPLAY_PAGE if the page desired does not exist, or was not detected
  1135.       by The C Window Library.
  1136.  
  1137.     NO_HEAP_MEM if there is no memory to save the initial screen.
  1138.  
  1139.     MAX_WINDOW if the maximum number of windows has already been defined.
  1140.  
  1141.  
  1142.  
  1143.   WindowInitialize()
  1144.   ------------------
  1145.  
  1146.   The next function is WindowInitialize().  This function sets up a window with
  1147.   the position on the screen to place the window, width, height, colors,
  1148.   and box type.  If successful, this function returns a new WPOINTER.  Here is
  1149.   an example:
  1150.  
  1151.         #include "window.h"
  1152.         #define  NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  1153.  
  1154.         WPOINTER w;
  1155.         main()
  1156.         {
  1157.           WindowInitializeSystem();
  1158.           WindowSaveInitial(0);
  1159.           w = WindowInitialize(BORDER,1,1,30,15,NORM,NORM,SINGLEBOX);
  1160.           ...
  1161.         }
  1162.  
  1163.   In the above example, we have defined a variable w as having a WPOINTER type.
  1164.   This variable will ultimately point to a valid WINDOW structure.  The first
  1165.   argument to WindowInitialize() is a constant called BORDER.  This tells the
  1166.   window manager that the window desired is going to have a border.  If no
  1167.   border was desired, the constant would be NOBORDER. The second and third
  1168.   arguments tells the window manager the row and column of the screen where the
  1169.   upper left corner of the window will be located.  Since the upper left corner
  1170.   of the screen is row 1, column 1, the upper left hand corner of the window
  1171.   will be placed at the upper left corner of the video screen.  The fourth and
  1172.   fifth argument denotes the width and the height of the window.  DO NOT
  1173.   INCLUDE THE BORDERS (if any) TO DETERMINE THE WIDTH AND HEIGHT OF THE WINDOW.
  1174.   Our window will have a width of 30 characters and a height of 15 characters.
  1175.   The sixth and seventh arguments are the video attributes of the inside of the
  1176.   window and the border respectively.
  1177.  
  1178.   The last argument tells us what type of border the window will have.  We use
  1179.   the constant SINGLEBOX to tell the window manager that we want a window with
  1180.  
  1181.  
  1182.  Page 10                     The C Window Library                    Page 10
  1183.  
  1184.   a border made up of single lines.
  1185.  
  1186.   If there is no error, WindowInitialize() returns a valid WPOINTER.
  1187.   If there is an error, WindowInitialize() returns a WIN_NULL_PTR (a null
  1188.   window pointer) and sets window_error_code to one of the following values:
  1189.  
  1190.    NO_HEAP_MEM if there is not enough memory to allocate for the window
  1191.      structure.
  1192.  
  1193.    BAD_WINDOW_SIZE if the dimensions for the window are too large for the
  1194.      physical screen.
  1195.  
  1196.    MAX_WINDOW if there are > 254 windows defined.
  1197.  
  1198.  
  1199.   Even though there is a structure type called WINDOW, you should always use
  1200.   the pointer to the structure (WPOINTER) rather than the WINDOW structure
  1201.   itself.
  1202.  
  1203.  
  1204.  
  1205.   CREATE_VIDEO_ATTRIBUTE() macro
  1206.   ------------------------------
  1207.  
  1208.   Please note the use of the macro CREATE_VIDEO_ATTRIBUTE() in the previous
  1209.   example to create an integer representing the foreground and background
  1210.   colors.  This macro uses the first argument as the background color, and the
  1211.   second argument is the foreground color.  In the above example we have a
  1212.   constant called NORM which uses CREATE_VIDEO_ATTRIBUTE() to create a black
  1213.   background and a white foreground color combination.
  1214.  
  1215.  
  1216.  
  1217.   Box types
  1218.   ---------
  1219.   For ease of use, There are predefined constants found in the vidsys.h
  1220.   header file that contains definitions of common border types.  These
  1221.   constants are as follows:
  1222.  
  1223.   DOUBLEBOX -- defines border characters for double box windows.
  1224.  
  1225.   SINGLEBOX -- defines border characters for single box windows.
  1226.  
  1227.   MIXEDBOX1 -- defines double lines for top and bottom and single lines on the
  1228.                sides.
  1229.  
  1230.   MIXEDBOX2 -- defines single lines for top and bottom and double lines on the
  1231.                sides.
  1232.  
  1233.   HATCHBOX1 -- defines a 'dotty' box.
  1234.  
  1235.   HATCHBOX2 -- Another 'dotty' box.
  1236.  
  1237.  
  1238.  Page 11                     The C Window Library                    Page 11
  1239.  
  1240.   HATCHBOX3 -- Yet another 'dotty' box.
  1241.  
  1242.   SOLIDBOX1 -- defines a box of solid characters.
  1243.  
  1244.   SOLIDBOX2 -- defines another box of different solid characters.
  1245.  
  1246.   BLANKBOX  -- defines a box with a blank border.  When using these characters,
  1247.                do not get confused with a window with no border, and a window
  1248.                with a blank border.
  1249.  
  1250.   DOTTEDLINE -- defines a box with dotted lines.
  1251.  
  1252.  
  1253.   Although there are predefined border types in The C Window Library, you can
  1254.   define your own types.  The window border characters are represented by an 8
  1255.   byte character string.  Each character in this string refers to a border
  1256.   character to be used in drawing the window border.  A list of what each
  1257.   position in the string stands for is as follows:
  1258.  
  1259.   position                Representation
  1260.   --------           ---------------------------
  1261.      0               Upper left corner character.
  1262.      1               Top line character.
  1263.      2               Upper right corner character.
  1264.      3               Left side character.
  1265.      4               Right side character.
  1266.      5               Bottom left corner character.
  1267.      6               Bottom line character.
  1268.      7               Bottom right corner character.
  1269.  
  1270.  
  1271.   This character string is sent to the window functions that call for a string
  1272.   of box drawing characters.  For example, you can create your own customized
  1273.   set of characters with something like this:
  1274.  
  1275.   #define MYBOXCHARS  "+-+||+-+"
  1276.  
  1277.   MYBOXCHARS is a literal string of box drawing characters.  Using the rules of
  1278.   box drawing characters defined above, the upper left hand corner of the box is
  1279.   the plus sign, the top line is the hyphen, the upper right and corner is the
  1280.   plus sign, the left side is a pipe character, as is the right side, and the
  1281.   bottom part of the box is defined the same as the upper part.  Then you would
  1282.   use it in a call to any function that asks for a box drawing string like this
  1283.  
  1284.              w = WindowInitialize(BORDER, ... ,MYBOXCHARS);
  1285.  
  1286.  
  1287.   The '... ' are the other arguments that you would normally put for the
  1288.   WindowInitialize() function.
  1289.  
  1290.  
  1291.  
  1292.  
  1293.  
  1294.  Page 12                     The C Window Library                    Page 12
  1295.  
  1296.                     OPENING WINDOWS FOR READING AND WRITING
  1297.                     ---------------------------------------
  1298.  
  1299.   The next step is to allocate memory for the window's text buffer.  This will
  1300.   allow writing and reading characters to the window even though it is not
  1301.   visible.
  1302.  
  1303.  
  1304.  
  1305.   WindowOpen()
  1306.   ------------
  1307.  
  1308.   The WindowOpen() function is used to allocate memory for the window's text
  1309.   buffer.  This function MUST be called if you are going to do many of the
  1310.   window functions.  Here is the previous example with the WindowOpen() call:
  1311.  
  1312.         #include "window.h"
  1313.         #define  NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  1314.  
  1315.         WPOINTER w;
  1316.         main()
  1317.         {
  1318.           WindowInitializeSystem();
  1319.           WindowSaveInitial(0);
  1320.           w = WindowInitialize(BORDER,1,1,20,15,NORM,NORM,SINGLEBOX);
  1321.           WindowOpen(w);
  1322.           ...
  1323.         }
  1324.  
  1325.  
  1326.   The WindowOpen() function does not display the window.  The argument tells
  1327.   the window manager what window to open.  In this case we want to open our new
  1328.   window, w.  The window buffer is cleared to spaces using the window's text
  1329.   attribute, and the border (if there is a border) is drawn internally.  When a
  1330.   window is opened with WindowOpen(), you can then write or read characters to
  1331.   a window, move, scroll, etc.  almost any function that you can do with a
  1332.   visible window.
  1333.  
  1334.   If there is no error, WindowOpen() returns NO_ERROR.
  1335.   If there is an error, WindowOpen() returns one of the following:
  1336.  
  1337.   1) NO_HEAP_MEM if there is not enough memory to allocate for the window
  1338.      buffer.
  1339.  
  1340.   2) BAD_WINDOW if the window does not exist.
  1341.  
  1342.  
  1343.  
  1344.  
  1345.  
  1346.  
  1347.  
  1348.  
  1349.  
  1350.  Page 13                     The C Window Library                    Page 13
  1351.  
  1352.                               DISPLAYING WINDOWS
  1353.                               ------------------
  1354.  
  1355.   Now we will display the window we created in the previous example.
  1356.  
  1357.  
  1358.   The WindowDisplay() function and Explosion Effects
  1359.   --------------------------------------------------
  1360.  
  1361.   The WindowDisplay() function displays a window.  Here is the previous
  1362.   example with WindowDisplay() added to it:
  1363.  
  1364.         #include "window.h"
  1365.         #define  NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  1366.  
  1367.         WPOINTER w;
  1368.         main()
  1369.         {
  1370.           WindowInitializeSystem();
  1371.           WindowSaveInitial(0);
  1372.           w = WindowInitialize(BORDER,1,1,20,15,NORM,NORM,SINGLEBOX);
  1373.           WindowOpen(w);
  1374.           WindowDisplay(w,1,NOEFFECT);
  1375.           ...
  1376.         }
  1377.  
  1378.   The first argument to WindowDisplay() is the window to display, in our case,
  1379.   w is the window.  The second argument is the rank order of the window.
  1380.   Since the rank order we desire is 1, this window will lie on top of all
  1381.   windows, unless another window is opened with a rank of 1.  Remember, any
  1382.   window with a rank number n will have windows with rank n-1, n-2,...,1 to be
  1383.   displayed on top of it.  You can change the rank order of a window at any
  1384.   time by calling WindowDisplay() with a different rank number.
  1385.  
  1386.   The third argument to WindowDisplay() is the explosion effect of the window
  1387.   when it is displayed.  There are currently 12 ways to explode a window on the
  1388.   screen, numbered from 0 thru 11.  Here is an overview of each effect:
  1389.  
  1390.  
  1391.         Defined Constant        Value            Effect
  1392.         ----------------        -----            ------
  1393.  
  1394.            NOEFFECT               0          ┌─────────────┐
  1395.                                              │             │
  1396.                                              │             │
  1397.                                              │             │
  1398.                                              │             │
  1399.                                              │             │
  1400.                                              │             │
  1401.                                              │             │
  1402.                                              └─────────────┘
  1403.  
  1404.  
  1405.  
  1406.  Page 14                     The C Window Library                    Page 14
  1407.  
  1408.            EXPLODE                1       ┌─────────────────┐
  1409.                                           │        ^        │
  1410.                                           │        |        │
  1411.                                           │        |        │
  1412.                                           │<--           -->│
  1413.                                           │                 │
  1414.                                           │        |        │
  1415.                                           │        |        │
  1416.                                           │        v        │
  1417.                                           └─────────────────┘
  1418.  
  1419.  
  1420.  
  1421.  
  1422.  
  1423.            CONTRACT               2       ┌─────────────────┐
  1424.                                           │        |        │
  1425.                                           │        |        │
  1426.                                           │        v        │
  1427.                                           │-->           <--│
  1428.                                           │        ^        │
  1429.                                           │        |        │
  1430.                                           │        |        │
  1431.                                           └─────────────────┘
  1432.  
  1433.  
  1434.            BRICKS                 3        ┌────────────────┐
  1435.                                            │█     █    █   █│
  1436.                                            │ █              │
  1437.                                            │     █     █  █ │
  1438.                                            │        █       │
  1439.                                            │  █  █    █   █ │
  1440.                                            │█        █      │
  1441.                                            └────────────────┘
  1442.  
  1443.  
  1444.  
  1445.  
  1446.                                                     ^
  1447.            MIDDLEROWOUT           4                 |
  1448.                                             ┌───────────────┐
  1449.                                             └───────────────┘
  1450.                                                     |
  1451.                                                     v
  1452.  
  1453.  
  1454.  
  1455.  
  1456.  
  1457.  
  1458.  
  1459.  
  1460.  
  1461.  
  1462.  Page 15                     The C Window Library                    Page 15
  1463.  
  1464.            TOPBOTTOMIN            5         ┌───────────────┐
  1465.                                             └───────────────┘
  1466.                                                     |
  1467.                                                     v
  1468.  
  1469.                                                     ^
  1470.                                                     |
  1471.                                             ┌───────────────┐
  1472.                                             └───────────────┘
  1473.  
  1474.  
  1475.  
  1476.  
  1477.  
  1478.  
  1479.  
  1480.            TOPDOWN                6         ┌───────────────┐
  1481.                                             └───────────────┘
  1482.                                                     |
  1483.                                                     v
  1484.  
  1485.  
  1486.  
  1487.  
  1488.  
  1489.  
  1490.                                                     ^
  1491.            BOTTOMUP               7                 |
  1492.                                             ┌───────────────┐
  1493.                                             └───────────────┘
  1494.  
  1495.  
  1496.  
  1497.  
  1498.            MIDDLECOLOUT           8                ┌┐
  1499.                                                    ││
  1500.                                                    ││
  1501.                                                    ││
  1502.                                                  <-││->
  1503.                                                    ││
  1504.                                                    ││
  1505.                                                    ││
  1506.                                                    └┘
  1507.  
  1508.  
  1509.  
  1510.  
  1511.  
  1512.  
  1513.  
  1514.  
  1515.  
  1516.  
  1517.  
  1518.  Page 16                     The C Window Library                    Page 16
  1519.  
  1520.            LEFTRIGHTIN            9              ┌┐      ┌┐
  1521.                                                  ││      ││
  1522.                                                  ││      ││
  1523.                                                  ││      ││
  1524.                                                  ││->  <-││
  1525.                                                  ││      ││
  1526.                                                  ││      ││
  1527.                                                  ││      ││
  1528.                                                  ││      ││
  1529.                                                  └┘      └┘
  1530.  
  1531.  
  1532.  
  1533.  
  1534.            LEFTTORIGHT            10             ┌┐
  1535.                                                  ││
  1536.                                                  ││
  1537.                                                  ││
  1538.                                                  ││->
  1539.                                                  ││
  1540.                                                  ││
  1541.                                                  ││
  1542.                                                  ││
  1543.                                                  └┘
  1544.  
  1545.  
  1546.  
  1547.  
  1548.  
  1549.            RIGHTTOLEFT            11             ┌┐
  1550.                                                  ││
  1551.                                                  ││
  1552.                                                  ││
  1553.                                                <-││
  1554.                                                  ││
  1555.                                                  ││
  1556.                                                  ││
  1557.                                                  ││
  1558.                                                  └┘
  1559.  
  1560.  
  1561.   If there is no error, WindowDisplay() will return NO_ERROR.
  1562.   If there is an error, WindowDisplay() will return one of the following:
  1563.  
  1564.   BAD_WINDOW if the window does not exist.
  1565.  
  1566.   WINDOW_NOT_OPEN if the window was not open with WindowOpen().
  1567.  
  1568.  
  1569.  
  1570.  
  1571.  
  1572.  
  1573.  
  1574.  Page 17                     The C Window Library                    Page 17
  1575.  
  1576.   Displaying Multiple Windows
  1577.   ---------------------------
  1578.  
  1579.   If you are creating multiple windows you can change the rank of the window by
  1580.   calling WindowDisplay() with a different rank number.  Here is an example:
  1581.  
  1582.  
  1583.  
  1584.    #include "window.h"
  1585.    #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)  /* define video
  1586.                                                           attribute */
  1587.    #define BLUEONBLACK  CREATE_VIDEO_ATTRIBUTE(black,blue)  /* define
  1588.                                                            video attribute */
  1589.    #define REDONBLACK   CREATE_VIDEO_ATTRIBUTE(black,red)
  1590.    #define GREENONBLACK CREATE_VIDEO_ATTRIBUTE(black,green)
  1591.  
  1592.    main()
  1593.    {
  1594.      int i;
  1595.      WPOINTER w1,w2,w3;             /* pointers to a window structures */
  1596.      WindowInitializeSystem();     /* system initialization function */
  1597.      WindowSaveInitial(0);
  1598.      w1 = WindowInitialize(BORDER,          /* Window has a border */
  1599.             1,               /* row on the screen to open window */
  1600.             1,               /* column on screen to open window */
  1601.             30,              /* width in characters of the window */
  1602.             15,              /* height of characters in window */
  1603.             BLUEONBLACK,     /* video attribute of text area of window */
  1604.             NORM,            /* video attribute of border */
  1605.             SINGLEBOX);      /* type of border to draw */
  1606.  
  1607.      /* define second window */
  1608.      w2 = WindowInitialize(BORDER,3,3,30,15,REDONBLACK,NORM,DOUBLEBOX);
  1609.  
  1610.      /* define third window */
  1611.  
  1612.      w3 = WindowInitialize(BORDER,5,5,30,15,GREENONBLACK,NORM,SINGLEBOX);
  1613.  
  1614.      WindowOpen(w1);      /* make window 1 ok to write */
  1615.  
  1616.      WindowOpen(w2);      /* make window 2 ok to write */
  1617.  
  1618.      WindowOpen(w3);      /* make window 3 ok to write */
  1619.  
  1620.      WindowDisplay(w1,1,NOEFFECT);
  1621.      WindowDisplay(w2,2,NOEFFECT);
  1622.      WindowDisplay(w3,3,NOEFFECT);
  1623.  
  1624.      GET_KEY();
  1625.  
  1626.      WindowDisplay(w2,1,NOEFFECT);
  1627.  
  1628.      GET_KEY();
  1629.  
  1630.  Page 18                     The C Window Library                    Page 18
  1631.  
  1632.      WindowDisplay(w3,1,NOEFFECT);
  1633.  
  1634.      GET_KEY();
  1635.  
  1636.      WindowDisplay(w1,1,NOEFFECT);
  1637.  
  1638.      GET_KEY();
  1639.    }
  1640.  
  1641.  
  1642.  
  1643.   In the above program, w1, w2, and w3 are displayed with rank numbers of 1, 2,
  1644.   and 3, respectively.  The ordering means that w1 will overlay w2, and w2 will
  1645.   overlay w3.
  1646.  
  1647.   Note that after the windows w1, w2, and w3 are initially displayed, they are
  1648.   redisplayed by making another call to WindowDisplay().  You can redisplay a
  1649.   window and change its rank by calling the WindowDisplay() function again.  For
  1650.   example, w2 is redisplayed with a rank of 1.  This promotes w2 to the top of
  1651.   the stack of displayed windows, and demotes w1 with a rank of 2.  Each and
  1652.   every window has a unique rank number.  The window manager keeps track of
  1653.   conflicts in rank numbers, and adjusts the data structures involved in
  1654.   maintaining the windows in working order.  Therefore, there is really no need
  1655.   for you to remember whether a rank number is used or not.
  1656.  
  1657.   The macro GET_KEY() pauses the program until you press a key.
  1658.  
  1659.  
  1660.  
  1661.  
  1662.  
  1663.  
  1664.  
  1665.  
  1666.  
  1667.  
  1668.  
  1669.  
  1670.  
  1671.  
  1672.  
  1673.  
  1674.  
  1675.  
  1676.  
  1677.  
  1678.  
  1679.  
  1680.  
  1681.  
  1682.  
  1683.  
  1684.  
  1685.  
  1686.  Page 19                     The C Window Library                    Page 19
  1687.  
  1688.                                 CLOSING WINDOWS
  1689.                                 ---------------
  1690.  
  1691.   In this section, we will discuss closing windows with and without destroying
  1692.   the window pointer.
  1693.  
  1694.  
  1695.  
  1696.   WindowClose()
  1697.   -------------
  1698.  
  1699.   The WindowClose() function hides a window from the screen and deallocates any
  1700.   memory that was allocated by the WindowOpen() function described in the
  1701.   previous section.  This DOES NOT destroy the window pointer (WPOINTER),
  1702.   however you must call WindowOpen() again if you want to use this window again
  1703.   for most other window functions.  Here is the prototype:
  1704.  
  1705.  
  1706.                  int WindowClose(WPOINTER w, int effect)
  1707.  
  1708.   The first argument is the window.  The second argument is the special effect
  1709.   to use when closing the window.  This argument is only meaningful if the
  1710.   window is visible.  For a list of effects refer back to the DISPLAYING
  1711.   WINDOWS section.  This function can be used if you are short of memory, but
  1712.   you do not want to destroy the WPOINTER.
  1713.  
  1714.  
  1715.  
  1716.   Example:
  1717.  
  1718.  
  1719.    #include "window.h"
  1720.    #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)  /* define video
  1721.                                                           attribute */
  1722.    #define BLUEONBLACK  CREATE_VIDEO_ATTRIBUTE(black,blue)  /* define
  1723.                                                            video attribute */
  1724.    #define REDONBLACK   CREATE_VIDEO_ATTRIBUTE(black,red)
  1725.    #define GREENONBLACK CREATE_VIDEO_ATTRIBUTE(black,green)
  1726.  
  1727.    main()
  1728.    {
  1729.      int i;
  1730.      WPOINTER w1,w2,w3;             /* pointers to a window structures */
  1731.      WindowInitializeSystem();     /* system initialization function */
  1732.      WindowSaveInitial(0);
  1733.      w1 = WindowInitialize(BORDER,          /* Window has a border */
  1734.             1,               /* row on the screen to open window */
  1735.             1,               /* column on screen to open window */
  1736.  
  1737.             30,              /* width in characters of the window */
  1738.             15,              /* height of characters in window */
  1739.             BLUEONBLACK,     /* video attribute of text area of window */
  1740.             NORM,            /* video attribute of border */
  1741.  
  1742.  Page 20                     The C Window Library                    Page 20
  1743.  
  1744.             SINGLEBOX);      /* type of border to draw */
  1745.  
  1746.      /* define second window */
  1747.      w2 = WindowInitialize(BORDER,3,3,30,15,REDONBLACK,NORM,DOUBLEBOX);
  1748.  
  1749.      /* define third window */
  1750.  
  1751.      w3 = WindowInitialize(BORDER,5,5,30,15,GREENONBLACK,NORM,SINGLEBOX);
  1752.  
  1753.      WindowOpen(w1);      /* make window 1 ok to write */
  1754.  
  1755.      WindowOpen(w2);      /* make window 2 ok to write */
  1756.  
  1757.      WindowOpen(w3);      /* make window 3 ok to write */
  1758.  
  1759.      WindowDisplay(w1,1,NOEFFECT);
  1760.      WindowDisplay(w2,2,NOEFFECT);
  1761.      WindowDisplay(w3,3,NOEFFECT);
  1762.  
  1763.      GET_KEY();
  1764.  
  1765.      WindowDisplay(w2,1,NOEFFECT);
  1766.  
  1767.      GET_KEY();
  1768.  
  1769.      WindowDisplay(w3,1,NOEFFECT);
  1770.  
  1771.      GET_KEY();
  1772.  
  1773.      WindowDisplay(w1,1,NOEFFECT);
  1774.  
  1775.      GET_KEY();
  1776.  
  1777.      WindowClose(w2,NOEFFECT);
  1778.  
  1779.      GET_KEY();
  1780.  
  1781.      WindowClose(w3,NOEFFECT);
  1782.  
  1783.      GET_KEY();
  1784.  
  1785.      WindowClose(w1,NOEFFECT);
  1786.    }
  1787.  
  1788.  
  1789.   The example above calls WindowClose() on all three windows.
  1790.  
  1791.  
  1792.   If there are no errors, WindowClose() returns NO_ERROR.
  1793.   If there are errors, WindowClose() returns the following value:
  1794.  
  1795.   BAD_WINDOW if the window w does not exist.
  1796.  
  1797.  
  1798.  Page 21                     The C Window Library                    Page 21
  1799.  
  1800.   WindowFree()
  1801.   ------------
  1802.  
  1803.   The WindowFree() function acts just like the WindowClose() function except
  1804.   that the WPOINTER is also deallocated.  This means that the WPOINTER cannot
  1805.   be used anymore unless it is initialized again using WindowInitialize(), or
  1806.   is assigned to another valid WPOINTER.  Here is the prototype:
  1807.  
  1808.                int WindowFree(WPOINTER w, int effect)
  1809.  
  1810.   Refer to WindowClose() for definitions of arguments and return values.
  1811.  
  1812.  
  1813.  
  1814.   WindowCloseAll()
  1815.   ----------------
  1816.  
  1817.   The WindowCloseAll() function acts just like WindowClose() function except
  1818.   that all windows are closed on a desired video page.  Here is the prototype:
  1819.  
  1820.                int WindowCloseAll(int page, int effect)
  1821.  
  1822.   The page argument is the video page of where the windows are located.
  1823.   Remember that The C Window Library allows displaying windows on video pages
  1824.   other than page 0 (default page).  The effect argument is the special effect
  1825.   to use when closing the window.  Refer to DISPLAYING WINDOWS for the
  1826.   list of special effects.
  1827.  
  1828.  
  1829.   Example:
  1830.  
  1831.  
  1832.    #include "window.h"
  1833.    #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)  /* define video
  1834.                                                           attribute */
  1835.    #define BLUEONBLACK  CREATE_VIDEO_ATTRIBUTE(black,blue)  /* define
  1836.                                                            video attribute */
  1837.    #define REDONBLACK   CREATE_VIDEO_ATTRIBUTE(black,red)
  1838.    #define GREENONBLACK CREATE_VIDEO_ATTRIBUTE(black,green)
  1839.  
  1840.    main()
  1841.    {
  1842.      int i;
  1843.      WPOINTER w1,w2,w3;             /* pointers to a window structures */
  1844.      WindowInitializeSystem();     /* system initialization function */
  1845.      WindowSaveInitial(0);
  1846.      w1 = WindowInitialize(BORDER,          /* Window has a border */
  1847.             1,               /* row on the screen to open window */
  1848.             1,               /* column on screen to open window */
  1849.  
  1850.             30,              /* width in characters of the window */
  1851.             15,              /* height of characters in window */
  1852.             BLUEONBLACK,     /* video attribute of text area of window */
  1853.  
  1854.  Page 22                     The C Window Library                    Page 22
  1855.  
  1856.  
  1857.             NORM,            /* video attribute of border */
  1858.             SINGLEBOX);      /* type of border to draw */
  1859.  
  1860.      /* define second window */
  1861.      w2 = WindowInitialize(BORDER,3,3,30,15,REDONBLACK,NORM,DOUBLEBOX);
  1862.  
  1863.      /* define third window */
  1864.  
  1865.      w3 = WindowInitialize(BORDER,5,5,30,15,GREENONBLACK,NORM,SINGLEBOX);
  1866.  
  1867.      WindowOpen(w1);      /* make window 1 ok to write */
  1868.      WindowOpen(w2);      /* make window 2 ok to write */
  1869.      WindowOpen(w3);      /* make window 3 ok to write */
  1870.      WindowDisplay(w1,1,NOEFFECT);
  1871.      WindowDisplay(w2,2,NOEFFECT);
  1872.      WindowDisplay(w3,3,NOEFFECT);
  1873.      WindowCloseAll(0,NOEFFECT);     /* close all the windows */
  1874.    }
  1875.  
  1876.  
  1877.   The example above calls WindowCloseAll() to close all three windows.
  1878.  
  1879.   Refer to WindowClose() for return values.
  1880.  
  1881.  
  1882.  
  1883.   WindowFreeAll()
  1884.   ---------------
  1885.  
  1886.   The WindowFreeAll() function acts just like WindowClose() function except
  1887.   that all windows are freed on a desired video page.  Here is the prototype:
  1888.  
  1889.                int WindowFreeAll(int page, int effect)
  1890.  
  1891.   The page argument is the video page of where the windows are located.
  1892.   Remember that The C Window Library allows displaying windows on video pages
  1893.   other than page 0 (default page).  The effect argument is the special effect
  1894.   to use when closing the window.  Refer to DISPLAYING WINDOWS for the list of
  1895.   special effects.
  1896.  
  1897.   Refer to WindowCloseAll() for return values.
  1898.  
  1899.  
  1900.  
  1901.  
  1902.  
  1903.  
  1904.  
  1905.  
  1906.  
  1907.  
  1908.  
  1909.  
  1910.  Page 23                     The C Window Library                    Page 23
  1911.  
  1912.                         CENTERING WINDOWS ON THE SCREEN
  1913.                         -------------------------------
  1914.  
  1915.   The C Window Library allows easy centering of windows on the screen.
  1916.  
  1917.  
  1918.   WindowCenter()
  1919.   ______________
  1920.  
  1921.  
  1922.   The WindowCenter() function centers a window on the screen vertically,
  1923.   horizontally, or both.  Here is the prototype:
  1924.  
  1925.                int WindowCenter(WPOINTER w, int option)
  1926.  
  1927.   The first argument is the window to center, and the second argument tells
  1928.   whether to center the window horizontally, vertically, or both.  The options
  1929.   argument must be one of the following:
  1930.  
  1931.          Value of
  1932.          options                    Type of centering
  1933.          -------                    -----------------
  1934.  
  1935.        VERTCENTER                       vertical
  1936.  
  1937.        HORIZCENTER                     horizontal
  1938.  
  1939.        VERTCENTER | HORIZCENTER     both horizontal and vertical
  1940.  
  1941.  
  1942.   Note the bitwise OR (|) between the constants VERTCENTER and HORIZCENTER for
  1943.   both horizontal and vertical centering.  This function can be used on hidden
  1944.   windows and windows that have not been opened with WindowOpen().
  1945.  
  1946.  
  1947.   Example:
  1948.  
  1949.  
  1950.   #include "window.h"
  1951.  
  1952.   #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  1953.  
  1954.   WPOINTER w;
  1955.  
  1956.   main()
  1957.   {
  1958.     WindowInitializeSystem();
  1959.     WindowSaveInitial(0);
  1960.     w = WindowInitialize(BORDER,1,1,10,10,NORM,NORM,SINGLEBOX);
  1961.     WindowOpen(w);
  1962.     WindowDisplay(w,1,NOEFFECT);
  1963.     GET_KEY();
  1964.  
  1965.  
  1966.  Page 24                     The C Window Library                    Page 24
  1967.  
  1968.  
  1969.     WindowCenter(w,VERTCENTER);  /* center window vertically */
  1970.     GET_KEY();
  1971.     WindowMove(w,1,1);
  1972.     GET_KEY();
  1973.     WindowCenter(w,HORIZCENTER); /* center window horizontally */
  1974.     GET_KEY();
  1975.     WindowMove(w,1,1);
  1976.     GET_KEY();
  1977.     WindowCenter(w,VERTCENTER | HORIZCENTER); /* center both horizontal and
  1978.                                                  vertical */
  1979.     GET_KEY();
  1980.     WindowFree(w,NOEFFECT);
  1981.   }
  1982.  
  1983.  
  1984.   If there are no errors, WindowCenter() returns NO_ERROR.
  1985.   If there is an error, the following value is returned:
  1986.  
  1987.      BAD_WINDOW if the window does not exist.
  1988.  
  1989.  
  1990.  
  1991.  
  1992.  
  1993.  
  1994.  
  1995.  
  1996.  
  1997.  
  1998.  
  1999.  
  2000.  
  2001.  
  2002.  
  2003.  
  2004.  
  2005.  
  2006.  
  2007.  
  2008.  
  2009.  
  2010.  
  2011.  
  2012.  
  2013.  
  2014.  
  2015.  
  2016.  
  2017.  
  2018.  
  2019.  
  2020.  
  2021.  
  2022.  Page 25                     The C Window Library                    Page 25
  2023.  
  2024.                         CHANGING WINDOW CHARACTERISTICS
  2025.                         -------------------------------
  2026.  
  2027.   In this section, we will discuss changing the window attributes, border
  2028.   style, and the window's height and width.
  2029.  
  2030.  
  2031.   WindowChangeTextAttribute()
  2032.   ---------------------------
  2033.  
  2034.  
  2035.   This function changes the attribute of the text portion of the window.  The
  2036.   text portion is the inside of the window.  Here is a prototype:
  2037.  
  2038.        int WindowChangeTextAttribute(WPOINTER w, int color)
  2039.  
  2040.   where w is the WPOINTER to change the text attribute, and color is the new
  2041.   color.  You can use the CREATE_VIDEO_ATTRIBUTE() macro to define the color.
  2042.  
  2043.   Example:
  2044.  
  2045.   #include "window.h"
  2046.  
  2047.   #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  2048.   #define REVERSE CREATE_VIDEO_ATTRIBUTE(white,black)
  2049.  
  2050.   WPOINTER w;
  2051.  
  2052.   main()
  2053.   {
  2054.     WindowInitializeSystem();
  2055.     WindowSaveInitial(0);
  2056.     w = WindowInitialize(BORDER,1,1,10,10,NORM,NORM,SINGLEBOX);
  2057.     WindowOpen(w);
  2058.     WindowDisplay(w,1,NOEFFECT);
  2059.     GET_KEY();
  2060.     WindowChangeTextAttribute(w,REVERSE);
  2061.   }
  2062.  
  2063.   If there is no error, WindowChangeTextAttribute() returns NO_ERROR.
  2064.   If there is an error, the following value is returned:
  2065.  
  2066.      BAD_WINDOW if the window does not exist.
  2067.  
  2068.  
  2069.  
  2070.  
  2071.  
  2072.  
  2073.  
  2074.  
  2075.  
  2076.  
  2077.  
  2078.  Page 26                     The C Window Library                    Page 26
  2079.  
  2080.   WindowChangeBorderAttribute()
  2081.   -----------------------------
  2082.  
  2083.   This function changes the video attribute of the border of the window.  If
  2084.   the window does not have a border, nothing is changed.  Here is a prototype:
  2085.  
  2086.        int WindowChangeBorderAttribute(WPOINTER w, int color)
  2087.  
  2088.   where w is the WPOINTER to change the border attribute, and color is the new
  2089.   color.  You can use the CREATE_VIDEO_ATTRIBUTE() macro to define the color.
  2090.  
  2091.  
  2092.  
  2093.   Example:
  2094.  
  2095.  
  2096.   #include "window.h"
  2097.  
  2098.   #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  2099.   #define REVERSE CREATE_VIDEO_ATTRIBUTE(white,black)
  2100.  
  2101.   WPOINTER w;
  2102.  
  2103.   main()
  2104.   {
  2105.     WindowInitializeSystem();
  2106.     WindowSaveInitial(0);
  2107.     w = WindowInitialize(BORDER,1,1,10,10,NORM,NORM,SINGLEBOX);
  2108.     WindowOpen(w);
  2109.     WindowDisplay(w,1,NOEFFECT);
  2110.     GET_KEY();
  2111.     WindowChangeBorderAttribute(w,REVERSE);
  2112.   }
  2113.  
  2114.   If there is no error, or if the window does not have a border,
  2115.   WindowChangeBorderAttribute() returns NO_ERROR.
  2116.  
  2117.   If there is an error, WindowChangeBorderAttribute() returns the following
  2118.   value:
  2119.  
  2120.      BAD_WINDOW if the WPOINTER w does not exist.
  2121.  
  2122.  
  2123.  
  2124.  
  2125.  
  2126.  
  2127.  
  2128.  
  2129.  
  2130.  
  2131.  
  2132.  
  2133.  
  2134.  Page 27                     The C Window Library                    Page 27
  2135.  
  2136.   WindowDrawBorder()
  2137.   ------------------
  2138.  
  2139.   You can also change the border type, or draw a border on an unbordered
  2140.   window by calling the WindowDrawBorder() function.
  2141.  
  2142.   Here is a prototype:
  2143.  
  2144.       int WindowDrawBorder(WPOINTER w, char *box)
  2145.  
  2146.   The first argument is the window we want to change the border of.  The
  2147.   second argument is a string of border characters.  This string denotes the
  2148.   type of border that the window should now have.  In the example given below,
  2149.   w is initialized with a SINGLEBOX border, but WindowDrawBorder() changes this
  2150.   to a DOUBLEBOX.
  2151.  
  2152.   The WindowDrawBorder() function is also used to draw borders on borderless
  2153.   windows.  When drawing borders on a NOBORDER window, the window must not have
  2154.   any of its sides touching the edges of the physical screen.  In other words,
  2155.   the window must "have room" for a border to be drawn.  If there is no room to
  2156.   draw the border, there is no change to the window.
  2157.  
  2158.   Example:
  2159.  
  2160.  
  2161.   #include "window.h"
  2162.  
  2163.   #define REVERSE   CREATE_VIDEO_ATTRIBUTE(white,black)
  2164.  
  2165.   WPOINTER w;
  2166.  
  2167.   main()
  2168.   {
  2169.     WindowInitializeSystem();
  2170.     WindowSaveInitial(0);
  2171.     w = WindowInitialize(NOBORDER,2,2,10,10,REVERSE,REVERSE,SINGLEBOX);
  2172.     WindowOpen(w);
  2173.     WindowDisplay(w,1,NOEFFECT);
  2174.     GET_KEY();
  2175.     WindowDrawBorder(w,DOUBLEBOX);  /* Draws a double box around NOBORDER
  2176.                                        window */
  2177.   }
  2178.  
  2179.  
  2180.   If there is no error, WindowDrawBorder() returns NO_ERROR.
  2181.   If there is an error, WindowDrawBorder() returns one of the following values:
  2182.  
  2183.   BAD_WINDOW if the window w does not exist.
  2184.  
  2185.   NO_HEAP_MEM if there is not enough memory to allocate for temporary buffer.
  2186.  
  2187.  
  2188.  
  2189.  
  2190.  Page 28                     The C Window Library                    Page 28
  2191.  
  2192.   WindowRemoveBorder()
  2193.   --------------------
  2194.  
  2195.   This function removes a border from a bordered window.  Here is the
  2196.   prototype:
  2197.  
  2198.        int WindowRemoveBorder(WPOINTER w)
  2199.  
  2200.   If the window does not have a border, nothing is changed.
  2201.  
  2202.   Example:
  2203.  
  2204.   #include "window.h"
  2205.   #define REVERSE   CREATE_VIDEO_ATTRIBUTE(white,black)
  2206.  
  2207.   WPOINTER w;
  2208.  
  2209.   main()
  2210.   {
  2211.     WindowInitializeSystem();
  2212.     WindowSaveInitial(0);
  2213.     w = WindowInitialize(BORDER,1,1,10,10,REVERSE,REVERSE,SINGLEBOX);
  2214.     WindowOpen(w);
  2215.     WindowDisplay(w,1,NOEFFECT);
  2216.     GET_KEY();
  2217.     WindowRemoveBorder(w);  /* Removes the double box around BORDERed
  2218.                                        window */
  2219.   }
  2220.  
  2221.   If there is no error, WindowRemoveBorder() returns NO_ERROR.
  2222.   If there is an error, WindowRemoveBorder returns one of the following values:
  2223.  
  2224.     BAD_WINDOW if the window w does not exist.
  2225.  
  2226.     NO_HEAP_MEM if there is not enough memory to allocate for temporary buffer.
  2227.  
  2228.  
  2229.  
  2230.   WindowResizeHeight()
  2231.   --------------------
  2232.  
  2233.   This function changes the inside (text portion) height of the window.  Here
  2234.   is a prototype:
  2235.  
  2236.     int WindowResizeHeight(WPOINTER w, int newheight, int anchor)
  2237.  
  2238.   The newheight argument is the new height of the window.  If the height will
  2239.   exceed the bounds of the screen, the window is given its maximum height.  The
  2240.   anchor argument determines which side to "hold down" while the window is
  2241.   being resized.  If the anchor is ANCHORTOP, the top line of the window is
  2242.   held in its current position and the window is resized accordingly.  If
  2243.   anchor is ANCHORBOTTOM, the bottom of the window is held and the window is
  2244.   resized accordingly.
  2245.  
  2246.  Page 29                     The C Window Library                    Page 29
  2247.  
  2248.   If there is text in the window, the text will be truncated if the window is
  2249.   made shorter (unless the window is a viewport to a virtual window.  Virtual
  2250.   windows are discussed in the VIRTUAL WINDOWS section).
  2251.  
  2252.   Example:
  2253.  
  2254.   #include "window.h"
  2255.  
  2256.   #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  2257.  
  2258.   WPOINTER w;
  2259.  
  2260.   main()
  2261.   {
  2262.     WindowInitializeSystem();
  2263.     WindowSaveInitial(0);
  2264.     w = WindowInitialize(BORDER,1,1,10,10,NORM,NORM,SINGLEBOX);
  2265.     WindowOpen(w);
  2266.     WindowDisplay(w,1,NOEFFECT);
  2267.     GET_KEY();
  2268.     WindowResizeHeight(w,15,ANCHORTOP);  /* Resize the window with a new
  2269.                                             height of 15 */
  2270.     GET_KEY();
  2271.     WindowResizeHeight(w,5,ANCHORBOTTOM); /* Resize window with new
  2272.                                              height of 5 */
  2273.   }
  2274.  
  2275.  
  2276.   If there were no errors, NO_ERROR is returned.
  2277.  
  2278.   If there is an error, WindowResizeHeight() returns one of the following
  2279.   values:
  2280.  
  2281.      BAD_WINDOW if the WPOINTER w does not exist.
  2282.  
  2283.      NO_HEAP_MEM if there was not enough memory to allocate for the resized
  2284.      window.
  2285.  
  2286.  
  2287.  
  2288.   WindowResizeWidth()
  2289.   -------------------
  2290.  
  2291.   This function changes the inside (text portion) width of the window.  Here
  2292.   is a prototype:
  2293.  
  2294.     int WindowResizeWidth(WPOINTER w, int newwidth, int anchor)
  2295.  
  2296.   The newwidth argument is the new width of the window.  If the width will
  2297.   exceed the bounds of the screen, the window is given its maximum width.  The
  2298.   anchor argument determines which side to "hold down" while the window is
  2299.   being resized.  If the anchor is ANCHORLEFT, the left side of the window is
  2300.   held in its current position and the window is resized accordingly.  If
  2301.  
  2302.  Page 30                     The C Window Library                    Page 30
  2303.  
  2304.   anchor is ANCHORRIGHT, the right side of the window is held and the window is
  2305.   resized accordingly.
  2306.  
  2307.   If there is text in the window, the text will be truncated if the window is
  2308.   made shorter (unless the window is a viewport to a virtual window.  Virtual
  2309.   windows are discussed in the VIRTUAL WINDOWS section).
  2310.  
  2311.  
  2312.   main()
  2313.   {
  2314.     WindowInitializeSystem();
  2315.     WindowSaveInitial(0);
  2316.     w = WindowInitialize(BORDER,1,1,10,10,NORM,NORM,SINGLEBOX);
  2317.     WindowOpen(w);
  2318.     WindowDisplay(w,1,NOEFFECT);
  2319.     GET_KEY();
  2320.     WindowResizeWidth(w,15,ANCHORLEFT);  /* Resize the window with a new
  2321.                                             width of 15 */
  2322.     GET_KEY();
  2323.     WindowResizeWidth(w,5,ANCHORRIGHT);   /* Resize window with new width
  2324.                                              of 5 */
  2325.   }
  2326.  
  2327.  
  2328.   If there were no errors, NO_ERROR is returned.
  2329.  
  2330.   If there is an error, WindowResizeWidth() returns one of the following:
  2331.  
  2332.      BAD_WINDOW if the WPOINTER w does not exist.
  2333.  
  2334.      NO_HEAP_MEM if there was not enough memory to allocate for the resized
  2335.      window.
  2336.  
  2337.  
  2338.  
  2339.  
  2340.  
  2341.  
  2342.  
  2343.  
  2344.  
  2345.  
  2346.  
  2347.  
  2348.  
  2349.  
  2350.  
  2351.  
  2352.  
  2353.  
  2354.  
  2355.  
  2356.  
  2357.  
  2358.  Page 31                     The C Window Library                    Page 31
  2359.  
  2360.  
  2361.  
  2362.  
  2363.  
  2364.  
  2365.  
  2366.                        This page intentionally left blank
  2367.  
  2368.  
  2369.  
  2370.  
  2371.  
  2372.  
  2373.  
  2374.  
  2375.  
  2376.  
  2377.  
  2378.  
  2379.  
  2380.  
  2381.  
  2382.  
  2383.  
  2384.  
  2385.  
  2386.  
  2387.  
  2388.  
  2389.  
  2390.  
  2391.  
  2392.  
  2393.  
  2394.  
  2395.  
  2396.  
  2397.  
  2398.  
  2399.  
  2400.  
  2401.  
  2402.  
  2403.  
  2404.  
  2405.  
  2406.  
  2407.  
  2408.  
  2409.  
  2410.  
  2411.  
  2412.  
  2413.  
  2414.  Page 32                     The C Window Library                    Page 32
  2415.  
  2416.                             WRITING TEXT TO WINDOWS
  2417.                             -----------------------
  2418.  
  2419.   There are various functions that will write text to a window.  These
  2420.   functions are divided into two groups: Functions that specify a null
  2421.   terminated string, and functions that require the length of the string of
  2422.   characters to write to be an explicit argument.
  2423.  
  2424.  
  2425.   Null Terminated Write Functions
  2426.   -------------------------------
  2427.  
  2428.   WindowWriteString()
  2429.   -------------------
  2430.  
  2431.   The WindowWriteString() function writes a null terminated string of characters
  2432.   to a window at a specified row and column of the window.  If the string is too
  2433.   long to fit in the boundaries of the window, the string is clipped (truncated)
  2434.   to fit in the boundaries of the window.
  2435.  
  2436.   Here is the prototype:
  2437.  
  2438.        int WindowWriteString(WPOINTER w, char *string, int row, int col)
  2439.  
  2440.   The first argument is the window to write the string to.  The second argument
  2441.   is the null terminated string to write.  The third and fourth arguments are
  2442.   the row and column of the window to place the string.  The video attribute
  2443.   used when writing the string is the video attribute of the inside of the
  2444.   window.
  2445.  
  2446.  
  2447.   Example:
  2448.  
  2449.  
  2450.   #include "window.h"
  2451.   #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  2452.  
  2453.   WPOINTER w;
  2454.   int i;
  2455.  
  2456.   main()
  2457.   {
  2458.     WindowInitializeSystem();
  2459.     WindowSaveInitial(0);
  2460.     w = WindowInitialize(BORDER,1,1,20,10,NORM,NORM,SINGLEBOX);
  2461.     WindowOpen(w);
  2462.     WindowDisplay(w,1,NOEFFECT);
  2463.     GET_KEY();
  2464.     for (i=1;i<=10;i++)
  2465.       WindowWriteString(w,"Hello World",i,1);
  2466.   }
  2467.  
  2468.  
  2469.  
  2470.  Page 33                     The C Window Library                    Page 33
  2471.  
  2472.   The above example writes the string "Hello World" to each line of the window
  2473.   w.
  2474.  
  2475.   If there is no error WindowWriteString() returns NO_ERROR.
  2476.   If there is an error WindowWriteString() returns the following:
  2477.  
  2478.   BAD_WINDOW if the WPOINTER w does not exist.
  2479.  
  2480.   WINDOW_BOUND if the row or column specified are out of bounds of the window.
  2481.  
  2482.   WINDOW_NOT_OPEN if the window was not open for writing (did not use
  2483.   WindowOpen() on the window)
  2484.  
  2485.  
  2486.  
  2487.   WindowWriteStringAttr()
  2488.   -----------------------
  2489.  
  2490.   The WindowWriteStringAttr() function works the same as the WindowWriteString()
  2491.   function except that an extra argument determines the color used to write the
  2492.   string.  Here is the prototype:
  2493.  
  2494.    int WindowWriteStringAttr(WPOINTER w, char *string, int row, int col,
  2495.                              int attr)
  2496.  
  2497.   The first argument is the window to write the string to.  The second argument
  2498.   is the null terminated string to write.  The third and fourth arguments are
  2499.   the row and column of the window to place the string. The last argument is the
  2500.   video attribute to use.
  2501.  
  2502.  
  2503.   Example:
  2504.  
  2505.  
  2506.   #include "window.h"
  2507.   #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  2508.   #define REVERSE CREATE_VIDEO_ATTRIBUTE(white,black)
  2509.  
  2510.   WPOINTER w;
  2511.   int i;
  2512.  
  2513.   main()
  2514.   {
  2515.     WindowInitializeSystem();
  2516.     WindowSaveInitial(0);
  2517.     w = WindowInitialize(BORDER,1,1,20,10,NORM,NORM,SINGLEBOX);
  2518.     WindowOpen(w);
  2519.     WindowDisplay(w,1,NOEFFECT);
  2520.     GET_KEY();
  2521.     for (i=1;i<=10;i++)
  2522.       WindowWriteStringAttr(w,"Hello World",i,1,REVERSE);
  2523.   }
  2524.  
  2525.  
  2526.  Page 34                     The C Window Library                    Page 34
  2527.  
  2528.   The above example writes the string "Hello World" to each line of the window
  2529.   w using the video attribute defined by the constant REVERSE.
  2530.  
  2531.   The return values to WindowWriteStringAttr() are the same as
  2532.   WindowWriteString().
  2533.  
  2534.  
  2535.  
  2536.   WindowWriteCenterString()
  2537.   -------------------------
  2538.  
  2539.   The WindowWriteCenterString() function centers a null terminated string in a
  2540.   window.  Here is a prototype:
  2541.  
  2542.       int WindowWriteCenterString(WPOINTER w, char *string, int row)
  2543.  
  2544.   The first argument is the window.  The second argument is the string to write.
  2545.   The third argument is the row that the string will be centered.
  2546.  
  2547.   The attribute used to write the string is the attribute of the inside of the
  2548.   window.
  2549.  
  2550.   Example:
  2551.  
  2552.   #include "window.h"
  2553.   #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  2554.  
  2555.   WPOINTER w;
  2556.   int i;
  2557.  
  2558.   main()
  2559.   {
  2560.     WindowInitializeSystem();
  2561.     WindowSaveInitial(0);
  2562.     w = WindowInitialize(BORDER,1,1,20,10,NORM,NORM,SINGLEBOX);
  2563.     WindowOpen(w);
  2564.     WindowDisplay(w,1,NOEFFECT);
  2565.     GET_KEY();
  2566.     for (i=1;i<=10;i++)
  2567.       WindowWriteCenterString(w,"Hello World",i);
  2568.   }
  2569.  
  2570.  
  2571.   The above example writes and centers the string "Hello World" to each line of
  2572.   the window w.
  2573.  
  2574.   The return values for WindowWriteCenterString() are the same as
  2575.   WindowWriteString().
  2576.  
  2577.  
  2578.  
  2579.  
  2580.  
  2581.  
  2582.  Page 35                     The C Window Library                    Page 35
  2583.  
  2584.   WindowWriteCenterStringAttr()
  2585.   -----------------------------
  2586.  
  2587.   The WindowWriteCenterStringAttr() function works the same as the
  2588.   WindowWriteCenterString() function except that an extra argument determines
  2589.   the color used to write the string.  Here is the prototype:
  2590.  
  2591.   int WindowWriteCenterStringAttr(WPOINTER w, char *string, int row, int attr)
  2592.  
  2593.   The first argument is the window.  The second argument is the string to write.
  2594.   The third argument is the row that the string will be centered.  The last
  2595.   argument is the video attribute to use to write the string.
  2596.  
  2597.   Example:
  2598.  
  2599.   #include "window.h"
  2600.   #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  2601.   #define REVERSE CREATE_VIDEO_ATTRIBUTE(white,black)
  2602.  
  2603.   WPOINTER w;
  2604.   int i;
  2605.  
  2606.   main()
  2607.   {
  2608.     WindowInitializeSystem();
  2609.     WindowSaveInitial(0);
  2610.     w = WindowInitialize(BORDER,1,1,20,10,NORM,NORM,SINGLEBOX);
  2611.     WindowOpen(w);
  2612.     WindowDisplay(w,1,NOEFFECT);
  2613.     GET_KEY();
  2614.     for (i=1;i<=10;i++)
  2615.       WindowWriteCenterStringAttr(w,"Hello World",i,REVERSE);
  2616.   }
  2617.  
  2618.  
  2619.   The above example writes and centers the string "Hello World" to each line of
  2620.   the window w using REVERSE as the video attribute.
  2621.  
  2622.   The return values for WindowWriteCenterStringAttr() are the same as
  2623.   WindowWriteString().
  2624.  
  2625.  
  2626.  
  2627.   WindowWriteStringCC()
  2628.   ---------------------
  2629.  
  2630.   Centers and writes a string around a column of the window (the CC stands
  2631.   for Centered Column).  If the string is longer than the width of the window,
  2632.   the string is placed on column 1 of the window and is clipped at the right
  2633.   edge of the window.  Here is the prototype:
  2634.  
  2635.   The attribute used to write the string is the attribute of the inside of the
  2636.   window.
  2637.  
  2638.  Page 36                     The C Window Library                    Page 36
  2639.  
  2640.       int WindowWriteStringCC(WPOINTER w, char *string, int row)
  2641.  
  2642.   The first argument is the window.  The second argument is the string. The
  2643.   third argument is the row to write the string, and the last argument is the
  2644.   column to center the string on.
  2645.  
  2646.  
  2647.   Example:
  2648.  
  2649.  
  2650.   #include "window.h"
  2651.   #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  2652.  
  2653.   WPOINTER w;
  2654.  
  2655.   main()
  2656.   {
  2657.     WindowInitializeSystem();
  2658.     WindowSaveInitial(0);
  2659.     w = WindowInitialize(BORDER,1,1,20,10,NORM,NORM,SINGLEBOX);
  2660.     WindowOpen(w);
  2661.     WindowDisplay(w,1,NOEFFECT);
  2662.     GET_KEY();
  2663.     WindowWriteStringCC(w,"This",1,10);
  2664.     WindowWriteStringCC(w,"is",2,10);
  2665.     WindowWriteStringCC(w,"centered",3,10);
  2666.     WindowWriteStringCC(w,"around",4,10);
  2667.     WindowWriteStringCC(w,"column",5,10);
  2668.     WindowWriteStringCC(w,"10",6,10);
  2669.   }
  2670.  
  2671.   The example above writes the text centered around column 10 of the window w.
  2672.  
  2673.   The return values for WindowWriteStringCC() are the same as
  2674.   WindowWriteString().
  2675.  
  2676.  
  2677.  
  2678.  
  2679.   WindowWriteStringCCAttr()
  2680.   -------------------------
  2681.  
  2682.   The WindowWriteStringCCAttr() function works the same as the
  2683.   WindowWriteStringCC() function except that an extra argument determines
  2684.   the color used to write the string.  Here is the prototype:
  2685.  
  2686.   int WindowWriteStringCCAttr(WPOINTER w, char *string, int row, int col,
  2687.                               int attr)
  2688.  
  2689.   The first argument is the window.  The second argument is the string to write.
  2690.   The third argument is the row that the string will be centered.  The column
  2691.   argument is the column to center the string on. The last argument is the
  2692.   video attribute to use to write the string.
  2693.  
  2694.  Page 37                     The C Window Library                    Page 37
  2695.  
  2696.   Example:
  2697.  
  2698.  
  2699.   #include "window.h"
  2700.   #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  2701.   #define REVERSE CREATE_VIDEO_ATTRIBUTE(white,black)
  2702.  
  2703.   WPOINTER w;
  2704.  
  2705.   main()
  2706.   {
  2707.     WindowInitializeSystem();
  2708.     WindowSaveInitial(0);
  2709.     w = WindowInitialize(BORDER,1,1,20,10,NORM,NORM,SINGLEBOX);
  2710.     WindowOpen(w);
  2711.     WindowDisplay(w,1,NOEFFECT);
  2712.     GET_KEY();
  2713.     WindowWriteStringCCAttr(w,"This",1,10,REVERSE);
  2714.     WindowWriteStringCCAttr(w,"is",2,10,REVERSE);
  2715.     WindowWriteStringCCAttr(w,"centered",3,10,REVERSE);
  2716.     WindowWriteStringCCAttr(w,"around",4,10,REVERSE);
  2717.     WindowWriteStringCCAttr(w,"column",5,10,REVERSE);
  2718.     WindowWriteStringCCAttr(w,"10",6,10,REVERSE);
  2719.   }
  2720.  
  2721.  
  2722.   The example above writes the text centered around column 10 of the window w
  2723.   using the video attribute REVERSE.
  2724.  
  2725.   The return values for WindowWriteStringCCAttr() are the same as
  2726.   WindowWriteString().
  2727.  
  2728.  
  2729.  
  2730.   WindowWriteStringRJ()
  2731.   ---------------------
  2732.  
  2733.   The WindowWriteStringRJ() function writes a right justified string.  Here is
  2734.   the prototype:
  2735.  
  2736.      int WindowWriteStringRJ(WPOINTER w, char *string, int row, int col)
  2737.  
  2738.   The first argument is the window.  The second argument is the string. The
  2739.   third argument is the row to write the string, and the last argument is the
  2740.   column to place the right edge of the string.
  2741.  
  2742.  
  2743.   Example:
  2744.  
  2745.   #include "window.h"
  2746.   #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  2747.  
  2748.   WPOINTER w;
  2749.  
  2750.  Page 38                     The C Window Library                    Page 38
  2751.  
  2752.   main()
  2753.   {
  2754.     WindowInitializeSystem();
  2755.     WindowSaveInitial(0);
  2756.     w = WindowInitialize(BORDER,1,1,20,10,NORM,NORM,SINGLEBOX);
  2757.     WindowOpen(w);
  2758.     WindowDisplay(w,1,NOEFFECT);
  2759.     GET_KEY();
  2760.     WindowWriteStringRJ(w,"This",1,10);
  2761.     WindowWriteStringRJ(w,"is",2,10);
  2762.     WindowWriteStringRJ(w,"right",3,10);
  2763.     WindowWriteStringRJ(w,"justified",4,10);
  2764.     WindowWriteStringRJ(w,"on ",5,10);
  2765.     WindowWriteStringRJ(w,"column",6,10);
  2766.     WindowWriteStringRJ(w,"10",7,10);
  2767.   }
  2768.  
  2769.   The example above writes the text right justified on column 10 of the window
  2770.   w.
  2771.  
  2772.   The attribute used to write the string is the attribute of the inside of the
  2773.   window.
  2774.  
  2775.   The return values for WindowWriteStringRJ() are the same as
  2776.   WindowWriteString().
  2777.  
  2778.  
  2779.  
  2780.   WindowWriteStringRJAttr()
  2781.   -------------------------
  2782.  
  2783.   The WindowWriteStringRJAttr() function works the same as the
  2784.   WindowWriteStringRJ() function except that an extra argument determines the
  2785.   color used to write the string.  Here is the prototype:
  2786.  
  2787.   int WindowWriteStringRJAttr(WPOINTER w, char *string, int row, int col,
  2788.                               int attr)
  2789.  
  2790.   The first argument is the window.  The second argument is the string to write.
  2791.   The third argument is the row to write the string.  The col is the column to
  2792.   right justify the string. The last argument is the video attribute to use to
  2793.   write the string.
  2794.  
  2795.  
  2796.   Example:
  2797.  
  2798.  
  2799.   #include "window.h"
  2800.   #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  2801.   #define REVERSE CREATE_VIDEO_ATTRIBUTE(white,black)
  2802.  
  2803.   WPOINTER w;
  2804.  
  2805.  
  2806.  Page 39                     The C Window Library                    Page 39
  2807.  
  2808.   main()
  2809.   {
  2810.     WindowInitializeSystem();
  2811.     WindowSaveInitial(0);
  2812.     w = WindowInitialize(BORDER,1,1,20,10,NORM,NORM,SINGLEBOX);
  2813.     WindowOpen(w);
  2814.     WindowDisplay(w,1,NOEFFECT);
  2815.     GET_KEY();
  2816.     WindowWriteStringRJAttr(w,"This",1,10,REVERSE);
  2817.     WindowWriteStringRJAttr(w,"is",2,10,REVERSE);
  2818.     WindowWriteStringRJAttr(w,"right",3,10,REVERSE);
  2819.     WindowWriteStringRJAttr(w,"justified",4,10,REVERSE);
  2820.     WindowWriteStringRJAttr(w,"on ",5,10,REVERSE);
  2821.     WindowWriteStringRJAttr(w,"column",6,10,REVERSE);
  2822.     WindowWriteStringRJAttr(w,"10",7,10,REVERSE);
  2823.   }
  2824.  
  2825.   The example above writes the text right justified at  column 10 of the window
  2826.   w using the video attribute REVERSE.
  2827.  
  2828.   The return values for WindowWriteStringRJAttr() are the same as
  2829.   WindowWriteString().
  2830.  
  2831.  
  2832.  
  2833.  
  2834.   Length Controlled Write Functions
  2835.   ---------------------------------
  2836.  
  2837.   The upcoming functions must have the length explicitly stated as one of the
  2838.   arguments.  These functions do not stop writing characters if the null
  2839.   character in the string to write is reached.
  2840.  
  2841.  
  2842.  
  2843.  
  2844.   WindowWriteCharacters()
  2845.   -----------------------
  2846.  
  2847.   This function writes characters from a buffer to the window.  Here is the
  2848.   prototype:
  2849.  
  2850.   int WindowWriteCharacters(WPOINTER w, char *buffer, int row, int col,
  2851.                             int length)
  2852.  
  2853.   The first argument is the window.  The second argument is a pointer to the
  2854.   buffer where the characters are stored.  The third and fourth arguments are
  2855.   the (row,col) position in the window to write the string, and the last
  2856.   argument is the number of characters from buffer to write.  The attribute
  2857.   used is the attribute of the inside of the window.
  2858.  
  2859.  
  2860.  
  2861.  
  2862.  Page 40                     The C Window Library                    Page 40
  2863.  
  2864.   Example:
  2865.  
  2866.  
  2867.   #include "window.h"
  2868.   #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  2869.  
  2870.   WPOINTER w;
  2871.   char buf[] = "Hello World!!";
  2872.  
  2873.   main()
  2874.   {
  2875.     WindowInitializeSystem();
  2876.     WindowSaveInitial(0);
  2877.     w = WindowInitialize(BORDER,1,1,20,10,NORM,NORM,SINGLEBOX);
  2878.     WindowOpen(w);
  2879.     WindowDisplay(w,1,NOEFFECT);
  2880.     GET_KEY();
  2881.     WindowWriteCharacters(w,buf,1,1,11);  /* Writes "Hello World"   */
  2882.     WindowWriteCharacters(w,buf,2,1,13);  /* Writes "Hello World!!" */
  2883.   }
  2884.  
  2885.   The return values for WindowWriteCharacters() are the same as
  2886.   WindowWriteString().
  2887.  
  2888.  
  2889.  
  2890.  
  2891.   WindowWriteAttributes()
  2892.   -----------------------
  2893.  
  2894.   This function writes attributes from a buffer to the window.  Here is the
  2895.   prototype:
  2896.  
  2897.   int WindowWriteAttributes(WPOINTER w, char *buffer, int row, int col,
  2898.                             int length)
  2899.  
  2900.   The first argument is the window.  The second argument is a pointer to the
  2901.   buffer where the attributes are stored.  The third and fourth arguments are
  2902.   the (row,col) position in the window to write the string, and the last
  2903.   argument is the number of attributes from buffer to write.
  2904.  
  2905.  
  2906.   Example:
  2907.  
  2908.  
  2909.   #include "window.h"
  2910.   #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  2911.   #define REVERSE CREATE_VIDEO_ATTRIBUTE(white,black)
  2912.  
  2913.   WPOINTER w;
  2914.   char buf[13];
  2915.  
  2916.  
  2917.  
  2918.  Page 41                     The C Window Library                    Page 41
  2919.  
  2920.   main()
  2921.   {
  2922.     int i;
  2923.     WindowInitializeSystem();
  2924.     WindowSaveInitial(0);
  2925.     w = WindowInitialize(BORDER,1,1,20,10,NORM,NORM,SINGLEBOX);
  2926.     WindowOpen(w);
  2927.     WindowDisplay(w,1,NOEFFECT);
  2928.  
  2929.     for (i=0;i<13;i++)
  2930.       if (i % 2)
  2931.         buf[i] = NORM;
  2932.       else
  2933.         buf[i] = REVERSE;
  2934.  
  2935.     WindowWriteString(w,"Hello World!!",1,1);
  2936.     GET_KEY();
  2937.     WindowWriteAttributes(w,buf,1,1,13);  /* Writes alternating NORM and
  2938.                                              REVERSE attributes */
  2939.   }
  2940.  
  2941.  
  2942.   The return values for WindowWriteAttributes() are the same as
  2943.   WindowWriteString().
  2944.  
  2945.  
  2946.  
  2947.  
  2948.   WindowWriteCharAndAttr()
  2949.   ------------------------
  2950.  
  2951.   The WindowWriteCharAndAttr() function writes a string of character/attribute
  2952.   pairs to a window.  Use this function if you have created a string of
  2953.   character/attribute pairs, and want to output them easily.  The string
  2954.   consists of character and attributes in the following manner:
  2955.  
  2956.            char-attr-char-attr...
  2957.  
  2958.   Each character is followed by its corresponding video attribute.
  2959.  
  2960.  
  2961.   Here is the prototype:
  2962.  
  2963.   int WindowWriteCharAndAttr(WPOINTER w, char *buffer, int row, int col,
  2964.                              int length)
  2965.  
  2966.  
  2967.   The first argument is the window. The second is the buffer where the
  2968.   character and attributes are stored.  The third and fourth is the (row,col)
  2969.   position in the window to write, and the length argument is the number of
  2970.   character/attribute pairs from the buffer to write.  Please note the
  2971.   difference in the meaning of the length argument in this function as opposed
  2972.   to its use in the preceding functions.
  2973.  
  2974.  Page 42                     The C Window Library                    Page 42
  2975.  
  2976.   Example:
  2977.  
  2978.  
  2979.   #include "window.h"
  2980.   #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  2981.  
  2982.   WPOINTER w;
  2983.   char buf[26];
  2984.   char *str = "Hello World!!";
  2985.   main()
  2986.   {
  2987.     int i;
  2988.     WindowInitializeSystem();
  2989.     WindowSaveInitial(0);
  2990.     w = WindowInitialize(BORDER,1,1,20,10,NORM,NORM,SINGLEBOX);
  2991.     WindowOpen(w);
  2992.     WindowDisplay(w,1,NOEFFECT);
  2993.  
  2994.     for (i=0;i<26;i+=2,str++)
  2995.     {
  2996.       buf[i] = *str;
  2997.       buf[i+1] = NORM;
  2998.     }
  2999.  
  3000.     WindowWriteCharAndAttr(w,buf,1,1,13);
  3001.   }
  3002.  
  3003.  
  3004.   The return values for WindowWriteCharAndAttr() are the same as
  3005.   WindowWriteString().
  3006.  
  3007.  
  3008.  
  3009.   WindowWriteCharactersAttr()
  3010.   ---------------------------
  3011.  
  3012.   The WindowWriteCharactersAttr() function writes characters from a buffer to a
  3013.   window.  The difference between this function and WindowWriteCharacters() is
  3014.   that a video attribute is specified.  Here is the prototype:
  3015.  
  3016.     int WindowWriteCharactersAttr(WPOINTER w, char *buffer, int row, int col,
  3017.                                   int attr, int length)
  3018.  
  3019.   The attr argument is the video attribute to use when writing the characters.
  3020.  
  3021.  
  3022.   Example:
  3023.  
  3024.   #include "window.h"
  3025.   #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  3026.   #define REVERSE CREATE_VIDEO_ATTRIBUTE(white,black)
  3027.  
  3028.  
  3029.  
  3030.  Page 43                     The C Window Library                    Page 43
  3031.  
  3032.   WPOINTER w;
  3033.   char buf[] = "Hello World!!";
  3034.  
  3035.   main()
  3036.   {
  3037.     WindowInitializeSystem();
  3038.     WindowSaveInitial(0);
  3039.     w = WindowInitialize(BORDER,1,1,20,10,NORM,NORM,SINGLEBOX);
  3040.     WindowOpen(w);
  3041.     WindowDisplay(w,1,NOEFFECT);
  3042.     GET_KEY();
  3043.     WindowWriteCharactersAttr(w,buf,2,1,REVERSE,13);  /* Writes "Hello World!!"
  3044.                                                          using the REVERSE
  3045.                                                          attribute */
  3046.   }
  3047.  
  3048.  
  3049.   The return values for WindowWriteCharactersAttr() are the same as
  3050.   WindowWriteString().
  3051.  
  3052.  
  3053.  
  3054.   WindowWriteRepeatAttribute()
  3055.   ----------------------------
  3056.  
  3057.  
  3058.   The WindowWriteRepeatAttribute() function writes an attribute a specified
  3059.   number of times to a window.  Here is a prototype:
  3060.  
  3061.  
  3062.   int WindowWriteRepeatAttribute(WPOINTER w, int attr, int row, int col,
  3063.                                  int count)
  3064.  
  3065.  
  3066.   The attr argument is the attribute to use.  The count argument specifies the
  3067.   number of times to write the attribute attr to the window starting at
  3068.   (row,col).
  3069.  
  3070.   Example:
  3071.  
  3072.   #include "window.h"
  3073.   #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  3074.   #define REVERSE CREATE_VIDEO_ATTRIBUTE(white,black)
  3075.  
  3076.   WPOINTER w;
  3077.  
  3078.   main()
  3079.   {
  3080.     WindowInitializeSystem();
  3081.     WindowSaveInitial(0);
  3082.     w = WindowInitialize(BORDER,1,1,20,10,NORM,NORM,SINGLEBOX);
  3083.     WindowOpen(w);
  3084.     WindowDisplay(w,1,NOEFFECT);
  3085.  
  3086.  Page 44                     The C Window Library                    Page 44
  3087.  
  3088.     WindowWriteString(w,"Hello World!!",1,1);
  3089.     GET_KEY();
  3090.     WindowWriteRepeatAttribute(w,REVERSE,1,1,13);
  3091.   }
  3092.  
  3093.   The example above illustrates that the WindowWriteRepeatAttribute() writes
  3094.   the REVERSE attribute 13 times starting at row 1, column 1 of the window w.
  3095.  
  3096.   The return values for WindowWriteRepeatAttribute() are the same as
  3097.   WindowWriteString().
  3098.  
  3099.  
  3100.  
  3101.  
  3102.   WindowWriteRepeatCharacter()
  3103.   ----------------------------
  3104.  
  3105.   The WindowWriteRepeatCharacter() function writes a character a specified
  3106.   number of times to a window.  Here is a prototype:
  3107.  
  3108.  
  3109.   int WindowWriteRepeatCharacter(WPOINTER w, int ch, int row, int col,
  3110.                                  int count)
  3111.  
  3112.  
  3113.   The count argument is the character to use.  The count argument specifies the
  3114.   number of times to write the character ch to the window starting at (row,col).
  3115.  
  3116.   #include "window.h"
  3117.   #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  3118.   #define REVERSE CREATE_VIDEO_ATTRIBUTE(white,black)
  3119.  
  3120.   WPOINTER w;
  3121.  
  3122.   main()
  3123.   {
  3124.     WindowInitializeSystem();
  3125.     WindowSaveInitial(0);
  3126.     w = WindowInitialize(BORDER,1,1,20,10,NORM,NORM,SINGLEBOX);
  3127.     WindowOpen(w);
  3128.     WindowDisplay(w,1,NOEFFECT);
  3129.     WindowWriteRepeatCharacter(w,'a',1,1,5);
  3130.     WindowWriteRepeatCharacter(w,'b',2,1,5);
  3131.     WindowWriteRepeatCharacter(w,'c',3,1,5);
  3132.   }
  3133.  
  3134.   The example above illustrates that the WindowWriteRepeatCharacter() writes
  3135.   the letter 'a', 'b', and 'c' 5 times on rows 1, 2, and 3 respectively.
  3136.  
  3137.   The return values for WindowWriteRepeatCharacter() are the same as
  3138.   WindowWriteString().
  3139.  
  3140.  
  3141.  
  3142.  Page 45                     The C Window Library                    Page 45
  3143.  
  3144.   Formatted Write Functions
  3145.   -------------------------
  3146.  
  3147.   These functions write formatted output to windows just like the printf()
  3148.   function.  There are two functions that do this, namely WindowPrintf()
  3149.   and WindowPrintfAttr().  These functions use a format string that is similar
  3150.   to the format string found in printf().  For example, %d, %s, %lf, etc. and
  3151.   most of the escape sequences are supported.  The list of escape sequences
  3152.   supported are as follows:
  3153.  
  3154.                         \n - newline
  3155.                         \b - backspace
  3156.                         \t - tab
  3157.                         \a - bell
  3158.                         \r - carriage return
  3159.                         \x - hexadecimal
  3160.  
  3161.  
  3162.   Where output is placed in the window
  3163.   ------------------------------------
  3164.  
  3165.   The row and column of where the string will be written is determined by the
  3166.   window's logical cursor.  The logical cursor is advanced by both of these
  3167.   functions to one column position after the last character is printed.  If you
  3168.   want to start at a particular row and column of the window, you must move the
  3169.   cursor yourself by calling the WindowMoveCursor() function.  This function is
  3170.   explained later in the CURSOR POSITIONING IN WINDOWS section.  If the window
  3171.   is displayed, the logical cursor of the window is equivalent to the screen
  3172.   cursor.  If the output to the window will be obscured by other windows, the
  3173.   screen cursor will also be hidden.
  3174.  
  3175.   When the window is first opened using WindowOpen(), the logical cursor is
  3176.   automatically moved to (1,1) of the window.
  3177.  
  3178.  
  3179.   WindowSetWrap()
  3180.   ---------------
  3181.  
  3182.   With these functions, any text that will exceed the boundaries of the window
  3183.   will be wrapped to the next line.  If the output will exceed the last row of
  3184.   the window, the window is automatically scrolled up by one line.  This is the
  3185.   default action that is taken when characters exceed the right edge of the
  3186.   window.  If you want the output clipped instead of wrapped, you must set the
  3187.   window's wrap flag using the WindowSetWrap() function.
  3188.  
  3189.   The WindowSetWrap() function sets the window's wrap flag to either on or off.
  3190.   Here is the prototype:
  3191.  
  3192.               int WindowSetWrap(WPOINTER w, int option)
  3193.  
  3194.   The second argument will be 0 if you want to turn the wrap flag off, or 1 if
  3195.   you want to turn it on.  If the wrap flag is off, the output generated by
  3196.   WindowPrintf() and WindowPrintfAttr() will be terminated when the right edge
  3197.  
  3198.  Page 46                     The C Window Library                    Page 46
  3199.  
  3200.   of the window is reached.  If the wrap flag is on, the output is wrapped to
  3201.   the next line when the right edge is reached, and the window will be scrolled
  3202.   up by one line if the output will exceed the last row.
  3203.  
  3204.   You can set the wrap flag to a window at any time.
  3205.  
  3206.  
  3207.  
  3208.   WindowPrintf()
  3209.   --------------
  3210.  
  3211.   The WindowPrintf() function writes formatted output to the window.  Here is
  3212.   the prototype:
  3213.  
  3214.             int WindowPrintf(WPOINTER w, char *format [,arg1,...])
  3215.  
  3216.   The first argument is the window.  The second argument is a format string.
  3217.   The rest of the arguments are optional arguments that are written to the
  3218.   window.
  3219.  
  3220.   Example:
  3221.  
  3222.   #include "window.h"
  3223.   #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  3224.   WPOINTER w;
  3225.   char *s1 = "This string will wrap around to the next line\n";
  3226.   char *s2 = "This escape code will ring the bell \a";
  3227.   int i = 3;
  3228.   double j = 5.6;
  3229.  
  3230.   main()
  3231.   {
  3232.     WindowInitializeSystem();
  3233.     WindowSaveInitial(0);
  3234.     w = WindowInitialize(BORDER,1,1,30,10,NORM,NORM,SINGLEBOX);
  3235.     WindowOpen(w);
  3236.     WindowDisplay(w,1,NOEFFECT);
  3237.     WindowPrintf(w,"3+2 is equal to %d\n",3+2);
  3238.     GET_KEY();
  3239.     WindowPrintf(w,"i is equal to %d\nj is equal to %lf\n",i,j);
  3240.     GET_KEY();
  3241.     WindowPrintf(w,s1);
  3242.     GET_KEY();
  3243.     WindowPrintf(w,s2);
  3244.   }
  3245.  
  3246.   The above example illustrates how WindowPrintf() is used to print formatted
  3247.   strings.
  3248.  
  3249.   The return values for WindowPrintf() are the same as WindowWriteString().
  3250.  
  3251.  
  3252.  
  3253.  
  3254.  Page 47                     The C Window Library                    Page 47
  3255.  
  3256.   WindowPrintfAttr()
  3257.   ------------------
  3258.  
  3259.   The WindowPrintfAttr() function writes formatted output to the window.
  3260.   The difference between WindowPrintf() and WindowPrintfAttr() is that
  3261.   WindowPrintfAttr() uses a video attribute specified as an argument.  Here is
  3262.   the prototype:
  3263.  
  3264.       int WindowPrintfAttr(WPOINTER w, int attr, char *format [,arg1,...])
  3265.  
  3266.   The first argument is the window.  The second argument is the video
  3267.   attribute to use.  The third argument is the format string.  The rest of the
  3268.   arguments are optional arguments that are written to the window.
  3269.  
  3270.  
  3271.   Example:
  3272.  
  3273.   #include "window.h"
  3274.   #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  3275.   #define REVERSE CREATE_VIDEO_ATTRIBUTE(white,black)
  3276.  
  3277.   WPOINTER w;
  3278.   char *s1 = "This string will wrap around to the next line\n";
  3279.   char *s2 = "This escape code will ring the bell \a";
  3280.   int i = 3;
  3281.   double j = 5.6;
  3282.  
  3283.   main()
  3284.   {
  3285.     WindowInitializeSystem();
  3286.     WindowSaveInitial(0);
  3287.     w = WindowInitialize(BORDER,1,1,30,10,NORM,NORM,SINGLEBOX);
  3288.     WindowOpen(w);
  3289.     WindowDisplay(w,1,NOEFFECT);
  3290.     WindowPrintfAttr(w,REVERSE,"3+2 is equal to %d\n",3+2);
  3291.     GET_KEY();
  3292.     WindowPrintfAttr(w,REVERSE,"i is equal to %d\nj is equal to %lf\n",i,j);
  3293.     GET_KEY();
  3294.     WindowPrintfAttr(w,REVERSE,s1);
  3295.     GET_KEY();
  3296.     WindowPrintfAttr(w,REVERSE,s2);
  3297.   }
  3298.  
  3299.   The above example illustrates how WindowPrintfAttr() is used to print
  3300.   formatted strings.
  3301.  
  3302.   The return values for WindowPrintfAttr() are the same as WindowWriteString().
  3303.  
  3304.  
  3305.  
  3306.  
  3307.  
  3308.  
  3309.  
  3310.  Page 48                     The C Window Library                    Page 48
  3311.  
  3312.                            WRITING TITLES TO WINDOWS
  3313.                            -------------------------
  3314.  
  3315.   This section only applies to bordered windows.  There are two methods of
  3316.   writing text to the top or bottom border of a window.  Each method has its
  3317.   advantages and disadvantages.
  3318.  
  3319.   The first method is to explicitly write to the border of the window.  Except
  3320.   for the WindowPrintf...() functions, if you specify the row number to be 0,
  3321.   the text is written on the upper border of the window. If the row number is
  3322.   equal to the window height + 1, the text is written on the lower border of
  3323.   the window.  To access the window's height use the macro WINDOW_HEIGHT()
  3324.   described later in the WINDOW MACROS section.
  3325.  
  3326.   If you want to write a formatted string on the border of the window, use the
  3327.   standard library function sprintf() to create a string of formatted output,
  3328.   and then write this string with one of the WindowWrite...() functions.
  3329.  
  3330.   Any text that is written on the borders of a window are not retained if the
  3331.   window is resized using one of the WindowResize...() functions, or if the
  3332.   border is changed using WindowDrawBorder().  Therefore it is a good idea to
  3333.   maintain what is on the borders of the window in your own string variables.
  3334.  
  3335.  
  3336.   Example:
  3337.  
  3338.  
  3339.   #include "window.h"
  3340.   #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  3341.  
  3342.   WPOINTER w;
  3343.   int i;
  3344.  
  3345.   main()
  3346.   {
  3347.     WindowInitializeSystem();
  3348.     WindowSaveInitial(0);
  3349.     w = WindowInitialize(BORDER,1,1,20,10,NORM,NORM,SINGLEBOX);
  3350.     WindowOpen(w);
  3351.     WindowDisplay(w,1,NOEFFECT);
  3352.     GET_KEY();
  3353.  
  3354.     /* Specify row 0 to write on */
  3355.     WindowWriteCenterString(w,"This is a title",0);
  3356.  
  3357.     /* Now write title on bottom by using the height structure member */
  3358.  
  3359.     WindowWriteCenterString(w,"This is a title",w->height + 1);
  3360.   }
  3361.  
  3362.  
  3363.  
  3364.  
  3365.  
  3366.  Page 49                     The C Window Library                    Page 49
  3367.  
  3368.   The second method is writing a string of text to either the top or bottom
  3369.   border by using the WindowTitle...() functions.  The advantage of using these
  3370.   functions is that the strings are retained automatically if the window is
  3371.   resized or the border type is changed.  Another advantage is that if the
  3372.   title does not fit in the boundaries of the window, the title is truncated,
  3373.   but the full title is retained in a buffer.  If the window is later resized
  3374.   so that the title can fit, the full title will appear on the border.
  3375.  
  3376.   The disadvantage is that only one string of text is allowed for the top and
  3377.   bottom borders, and there are only three positions on each border to place
  3378.   the title.
  3379.  
  3380.  
  3381.   WindowTitleTop()
  3382.   ----------------
  3383.  
  3384.   The WindowTitleTop() function writes a title to the top border of a window.
  3385.   Here is the prototype:
  3386.  
  3387.             int WindowTitleTop(WPOINTER w, char *title, int pos)
  3388.  
  3389.   The first argument is the window to write the title.  The second argument is
  3390.   the title to write.  The third argument is the position to place the title.
  3391.   Here is a list of valid constants to use for the position:
  3392.  
  3393.  
  3394.      TITLELEFT - Places the title starting at column 1 of the window.
  3395.  
  3396.      TITLECENTER - Centers the title in the window.
  3397.  
  3398.      TITLERIGHT - Right justifies the title to the last column of the window.
  3399.  
  3400.  
  3401.   #include "window.h"
  3402.   #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  3403.  
  3404.   WPOINTER w;
  3405.   int i;
  3406.   main()
  3407.   {
  3408.     WindowInitializeSystem();
  3409.     WindowSaveInitial(0);
  3410.     w = WindowInitialize(BORDER,1,1,20,10,NORM,NORM,SINGLEBOX);
  3411.     WindowOpen(w);
  3412.     WindowDisplay(w,1,NOEFFECT);
  3413.     GET_KEY();
  3414.  
  3415.     /* left justify title */
  3416.     WindowTitleTop(w,"This is a title",TITLELEFT);
  3417.     GET_KEY();
  3418.  
  3419.  
  3420.  
  3421.  
  3422.  Page 50                     The C Window Library                    Page 50
  3423.  
  3424.     /* center title */
  3425.     WindowTitleTop(w,"This is a title",TITLECENTER);
  3426.     GET_KEY();
  3427.     /* right justify title */
  3428.     WindowTitleTop(w,"This is a title",TITLERIGHT);
  3429.   }
  3430.  
  3431.  
  3432.   If there are no errors, WindowTitleTop() returns NO_ERROR.
  3433.   If there are errors, WindowTitleTop() returns one of the following:
  3434.  
  3435.   BAD_WINDOW if the window does not exist.
  3436.  
  3437.   WINDOW_NOT_OPEN if the window was not open for writing (use WindowOpen())
  3438.  
  3439.  
  3440.  
  3441.   WindowTitleBottom()
  3442.   -------------------
  3443.  
  3444.   The WindowTitleBottom() function writes a title to the bottom border of a
  3445.   window.  Here is the prototype:
  3446.  
  3447.             int WindowTitleBottom(WPOINTER w, char *title, int pos)
  3448.  
  3449.   The first argument is the window to write the title.  The second argument is
  3450.   the title to write.  The third argument is a constant that denotes the
  3451.   position to place the title.  A list of valid constants can be found in the
  3452.   description of WindowTitleBottom() described above.
  3453.  
  3454.  
  3455.   #include "window.h"
  3456.   #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  3457.  
  3458.   WPOINTER w;
  3459.   int i;
  3460.   main()
  3461.   {
  3462.     WindowInitializeSystem();
  3463.     WindowSaveInitial(0);
  3464.     w = WindowInitialize(BORDER,1,1,20,10,NORM,NORM,SINGLEBOX);
  3465.     WindowOpen(w);
  3466.     WindowDisplay(w,1,NOEFFECT);
  3467.     GET_KEY();
  3468.  
  3469.     /* left justify title */
  3470.     WindowTitleBottom(w,"This is a title",TITLELEFT);
  3471.     GET_KEY();
  3472.  
  3473.     /* center title */
  3474.     WindowTitleBottom(w,"This is a title",TITLECENTER);
  3475.     GET_KEY();
  3476.  
  3477.  
  3478.  Page 51                     The C Window Library                    Page 51
  3479.  
  3480.     /* right justify title */
  3481.     WindowTitleBottom(w,"This is a title",TITLERIGHT);
  3482.   }
  3483.  
  3484.  
  3485.   If there are no errors, WindowTitleBottom() returns NO_ERROR.
  3486.   If there are errors, WindowTitleBottom() returns one of the following:
  3487.  
  3488.   BAD_WINDOW if the window does not exist.
  3489.  
  3490.   WINDOW_NOT_OPEN if the window was not open for writing (use WindowOpen())
  3491.  
  3492.  
  3493.  
  3494.  
  3495.  
  3496.   WindowTitleTopAttr()
  3497.   --------------------
  3498.  
  3499.   The WindowTitleTopAttr() function writes a title to the top border of a window
  3500.   with a specified color attribute.  Here is the prototype:
  3501.  
  3502.         int WindowTitleTopAttr(WPOINTER w, char *title, int pos, int attr)
  3503.  
  3504.   The first argument is the window to write the title.  The second argument is
  3505.   the title to write.  The third argument is a constant that denotes the
  3506.   position to place the title.  A list of valid constants can be found in the
  3507.   description of WindowTitleTopAttr() described above.  The fourth argument is
  3508.   the color attribute to use.
  3509.  
  3510.  
  3511.   #include "window.h"
  3512.   #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  3513.   #define REVERSE CREATE_VIDEO_ATTRIBUTE(white,black)
  3514.  
  3515.   WPOINTER w;
  3516.   int i;
  3517.   main()
  3518.   {
  3519.     WindowInitializeSystem();
  3520.     WindowSaveInitial(0);
  3521.     w = WindowInitialize(BORDER,1,1,20,10,NORM,NORM,SINGLEBOX);
  3522.     WindowOpen(w);
  3523.     WindowDisplay(w,1,NOEFFECT);
  3524.     GET_KEY();
  3525.  
  3526.     /* left justify title */
  3527.     WindowTitleTopAttr(w,"This is a title",TITLELEFT,REVERSE);
  3528.     GET_KEY();
  3529.  
  3530.     /* center title */
  3531.     WindowTitleTopAttr(w,"This is a title",TITLECENTER,REVERSE);
  3532.     GET_KEY();
  3533.  
  3534.  Page 52                     The C Window Library                    Page 52
  3535.  
  3536.     /* right justify title */
  3537.     WindowTitleTopAttr(w,"This is a title",TITLERIGHT,REVERSE);
  3538.   }
  3539.  
  3540.  
  3541.   If there are no errors, WindowTitleTopAttr() returns NO_ERROR.
  3542.   If there are errors, WindowTitleTopAttr() returns one of the following:
  3543.  
  3544.   BAD_WINDOW if the window does not exist.
  3545.  
  3546.   WINDOW_NOT_OPEN if the window was not open for writing (use WindowOpen())
  3547.  
  3548.  
  3549.  
  3550.  
  3551.   WindowTitleBottomAttr()
  3552.   -----------------------
  3553.  
  3554.   The WindowTitleBottomAttr() function writes a title to the bottom border of a
  3555.   window with a specified color attribute.  Here is the prototype:
  3556.  
  3557.         int WindowTitleBottomAttr(WPOINTER w, char *title, int pos, int attr)
  3558.  
  3559.   The first argument is the window to write the title.  The second argument is
  3560.   the title to write.  The third argument is a constant that denotes the
  3561.   position to place the title.  A list of valid constants can be found in the
  3562.   description of WindowTitleBottomAttr() described above.  The fourth argument is
  3563.   the color attribute to use.
  3564.  
  3565.  
  3566.   #include "window.h"
  3567.   #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  3568.   #define REVERSE CREATE_VIDEO_ATTRIBUTE(white,black)
  3569.  
  3570.   WPOINTER w;
  3571.   int i;
  3572.   main()
  3573.   {
  3574.     WindowInitializeSystem();
  3575.     WindowSaveInitial(0);
  3576.     w = WindowInitialize(BORDER,1,1,20,10,NORM,NORM,SINGLEBOX);
  3577.     WindowOpen(w);
  3578.     WindowDisplay(w,1,NOEFFECT);
  3579.     GET_KEY();
  3580.  
  3581.     /* left justify title */
  3582.     WindowTitleBottomAttr(w,"This is a title",TITLELEFT,REVERSE);
  3583.     GET_KEY();
  3584.  
  3585.     /* center title */
  3586.     WindowTitleBottomAttr(w,"This is a title",TITLECENTER,REVERSE);
  3587.     GET_KEY();
  3588.  
  3589.  
  3590.  Page 53                     The C Window Library                    Page 53
  3591.  
  3592.     /* right justify title */
  3593.     WindowTitleBottomAttr(w,"This is a title",TITLERIGHT,REVERSE);
  3594.   }
  3595.  
  3596.  
  3597.   If there are no errors, WindowTitleBottomAttr() returns NO_ERROR.
  3598.   If there are errors, WindowTitleBottomAttr() returns one of the following:
  3599.  
  3600.   BAD_WINDOW if the window does not exist.
  3601.  
  3602.   WINDOW_NOT_OPEN if the window was not open for writing (use WindowOpen())
  3603.  
  3604.  
  3605.  
  3606.  
  3607.  
  3608.  
  3609.  
  3610.  
  3611.  
  3612.  
  3613.  
  3614.  
  3615.  
  3616.  
  3617.  
  3618.  
  3619.  
  3620.  
  3621.  
  3622.  
  3623.  
  3624.  
  3625.  
  3626.  
  3627.  
  3628.  
  3629.  
  3630.  
  3631.  
  3632.  
  3633.  
  3634.  
  3635.  
  3636.  
  3637.  
  3638.  
  3639.  
  3640.  
  3641.  
  3642.  
  3643.  
  3644.  
  3645.  
  3646.  Page 54                     The C Window Library                    Page 54
  3647.  
  3648.                 READING CHARACTERS AND ATTRIBUTES FROM WINDOWS
  3649.                 ----------------------------------------------
  3650.  
  3651.   With The C Window Library, you can read the contents of a window into a
  3652.   character buffer.  These functions provide the programmer with the contents of
  3653.   the window at any time.  The functions to perform this are
  3654.   WindowReadAttributes(), WindowReadCharacters(), and WindowReadCharAndAttr().
  3655.  
  3656.  
  3657.  
  3658.   WindowReadCharacters()
  3659.   ----------------------
  3660.  
  3661.   The WindowReadCharacters() function reads the characters from a window into a
  3662.   buffer.  Here is the prototype.
  3663.  
  3664.   int WindowReadCharacters(WPOINTER w, char *buffer, int row, int col,
  3665.                            int length)
  3666.  
  3667.   The first argument is the window.  The second argument is the buffer to store
  3668.   the characters in.  The third and fourth arguments are the (row,col) position
  3669.   in the window to start reading from.  The last argument is the number of
  3670.   characters to read.
  3671.  
  3672.   You must make sure that buffer has enough room to hold all of the characters
  3673.   read in.
  3674.  
  3675.  
  3676.   Example:
  3677.  
  3678.   #include "window.h"
  3679.   #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  3680.  
  3681.   WPOINTER w;
  3682.   char buf[14] = {0};      /* Null all elements of buf */
  3683.  
  3684.   main()
  3685.   {
  3686.     int i;
  3687.     WindowInitializeSystem();
  3688.     WindowSaveInitial(0);
  3689.     w = WindowInitialize(BORDER,1,1,20,10,NORM,NORM,SINGLEBOX);
  3690.     WindowOpen(w);
  3691.     WindowDisplay(w,1,NOEFFECT);
  3692.     WindowWriteString(w,"Hello World!!",1,1);/* Write String */
  3693.     WindowReadCharacters(w,buf,1,1,13);      /* Read characters */
  3694.     GET_KEY();
  3695.     WindowWriteString(w,buf,2,1);            /* Write what we have read */
  3696.   }
  3697.  
  3698.  
  3699.  
  3700.  
  3701.  
  3702.  Page 55                     The C Window Library                    Page 55
  3703.  
  3704.   The example above illustrates the use of WindowReadCharacters(), which reads
  3705.   the window's contents starting at (1,1) of the window.  This happens to be
  3706.   the string "Hello World!!".  After GET_KEY() is called, the results of the
  3707.   buffer are written on line 2 of the window.
  3708.  
  3709.   If the length exceeds the right edge of the window, WindowReadCharacters()
  3710.   will read up to the right edge of the window.
  3711.  
  3712.  
  3713.   If there are no errors, WindowReadCharacters() returns NO_ERROR.
  3714.   If there are errors, WindowReadCharacters() returns one of the following:
  3715.  
  3716.   BAD_WINDOW if the window does not exist.
  3717.  
  3718.   WINDOW_NOT_OPEN if the window was not open for reading (use WindowOpen())
  3719.  
  3720.   WINDOW_BOUND if the row or column specified in the window is out of bounds.
  3721.  
  3722.  
  3723.  
  3724.  
  3725.   WindowReadAttributes()
  3726.   ----------------------
  3727.  
  3728.   The WindowReadAttributes() function reads the attributes from a window into a
  3729.   buffer.  Here is the prototype.
  3730.  
  3731.   int WindowReadAttributes(WPOINTER w, char *buffer, int row, int col,
  3732.                            int length)
  3733.  
  3734.   The first argument is the window.  The second argument is the buffer to store
  3735.   the attributes in.  The third and fourth arguments are the (row,col) position
  3736.   in the window to start reading from.  The last argument is the number of
  3737.   attributes to read.
  3738.  
  3739.   You must make sure that buffer has enough room to hold all of the attributes
  3740.   read in.
  3741.  
  3742.  
  3743.   Example:
  3744.  
  3745.   #include "window.h"
  3746.   #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  3747.  
  3748.   WPOINTER w;
  3749.   char buf[14] = {0};      /* Null all elements of buf */
  3750.  
  3751.   main()
  3752.   {
  3753.     int i;
  3754.     WindowInitializeSystem();
  3755.     WindowSaveInitial(0);
  3756.  
  3757.  
  3758.  Page 56                     The C Window Library                    Page 56
  3759.  
  3760.     w = WindowInitialize(BORDER,1,1,20,10,NORM,NORM,SINGLEBOX);
  3761.     WindowOpen(w);
  3762.     WindowDisplay(w,1,NOEFFECT);
  3763.     WindowWriteString(w,"Hello World!!",1,1);/* Write String */
  3764.     WindowReadAttributes(w,buf,1,1,13);      /* Read attributes */
  3765.     GET_KEY();
  3766.     WindowWriteString(w,buf,2,1);            /* Write what we have read */
  3767.   }
  3768.  
  3769.   The example above illustrates the use of WindowReadAttributes(), which reads
  3770.   the window's attribute contents starting at (1,1) of the window.  This
  3771.   happens to be the attributes of the string "Hello World!!", which is the
  3772.   NORM attribute.  After GET_KEY() is called, the results of the buffer are
  3773.   written on line 2 of the window.
  3774.  
  3775.   If the length exceeds the right edge of the window, WindowReadAttributes()
  3776.   will read up to the right edge of the window.
  3777.  
  3778.  
  3779.   If there are no errors, WindowReadAttributes() returns NO_ERROR.
  3780.   If there are errors, WindowReadAttributes() returns one of the following:
  3781.  
  3782.   BAD_WINDOW if the window does not exist.
  3783.  
  3784.   WINDOW_NOT_OPEN if the window was not open for reading (use WindowOpen())
  3785.  
  3786.   WINDOW_BOUND if the row or column specified in the window is out of bounds.
  3787.  
  3788.  
  3789.  
  3790.  
  3791.   WindowReadCharAndAttr()
  3792.   ----------------------
  3793.  
  3794.   The WindowReadCharAndAttr() function reads character/attribute pairs from a
  3795.   window into a buffer.  Here is the prototype.
  3796.  
  3797.   int WindowReadCharAndAttr(WPOINTER w, char *buffer, int row, int col,
  3798.                             int length)
  3799.  
  3800.   The first argument is the window.  The second argument is the buffer to store
  3801.   the character/attribute pairs in.  The third and fourth arguments are the
  3802.   (row,col) position in the window to start reading from.  The last argument is
  3803.   the number of character/attribute pairs to read.
  3804.  
  3805.   You must make sure that buffer has enough room to hold all of the
  3806.   character/attribute pairs read in.
  3807.  
  3808.  
  3809.  
  3810.  
  3811.  
  3812.  
  3813.  
  3814.  Page 57                     The C Window Library                    Page 57
  3815.  
  3816.   Example:
  3817.  
  3818.   #include "window.h"
  3819.   #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  3820.  
  3821.   WPOINTER w;
  3822.   char buf[27] = {0};      /* Null all elements of buf */
  3823.  
  3824.   main()
  3825.   {
  3826.     int i;
  3827.     WindowInitializeSystem();
  3828.     WindowSaveInitial(0);
  3829.     w = WindowInitialize(BORDER,1,1,20,10,NORM,NORM,SINGLEBOX);
  3830.     WindowOpen(w);
  3831.     WindowDisplay(w,1,NOEFFECT);
  3832.     WindowWriteString(w,"Hello World!!",1,1);/* Write String */
  3833.     WindowReadCharAndAttr(w,buf,1,1,13);      /* Read character/attributes */
  3834.     GET_KEY();
  3835.     WindowWriteCharAndAttr(w,buf,2,1,13);     /* Write what we have read */
  3836.   }
  3837.  
  3838.   The example above illustrates the use of WindowReadCharAndAttr(), which reads
  3839.   the window's character/attribute contents starting at (1,1) of the window.
  3840.   This happens to be the characters/attributes of the string "Hello World!!".
  3841.   After GET_KEY() is called, the results of the buffer are written on line 2 of
  3842.   the window.
  3843.  
  3844.   If the length exceeds the right edge of the window,
  3845.   WindowReadCharAndAttr() will read up to the right edge of the window.
  3846.  
  3847.  
  3848.   If there are no errors, WindowReadCharAndAttr() returns NO_ERROR.
  3849.   If there are errors, WindowReadCharAndAttr() returns one of the following:
  3850.  
  3851.   BAD_WINDOW if the window does not exist.
  3852.  
  3853.   WINDOW_NOT_OPEN if the window was not open for reading (use WindowOpen())
  3854.  
  3855.   WINDOW_BOUND if the row or column specified in the window is out of bounds.
  3856.  
  3857.  
  3858.  
  3859.  
  3860.  
  3861.  
  3862.  
  3863.  
  3864.  
  3865.  
  3866.  
  3867.  
  3868.  
  3869.  
  3870.  Page 58                     The C Window Library                    Page 58
  3871.  
  3872.                                 HIDING WINDOWS
  3873.                                 --------------
  3874.  
  3875.   With The C Window Library, you can hide windows at any time without
  3876.   disturbing the contents of other windows.
  3877.  
  3878.  
  3879.  
  3880.   WindowHide()
  3881.   ------------
  3882.  
  3883.   The WindowHide() function hides a window on the screen from view.  The window
  3884.   retains all text and shadows that may be present.  Here is a prototype:
  3885.  
  3886.                   int WindowHide(WPOINTER w, int effect)
  3887.  
  3888.   The first argument is the window, and the last argument is the special effect
  3889.   to use when hiding the window.  For a list of special effects, refer to the
  3890.   DISPLAYING WINDOWS section.
  3891.  
  3892.   Example :
  3893.  
  3894.  
  3895.   #include "window.h"
  3896.   #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  3897.   #define REDONWHITE  CREATE_VIDEO_ATTRIBUTE(red,white)
  3898.   #define BLACKONWHITE  CREATE_VIDEO_ATTRIBUTE(white,black)
  3899.  
  3900.  
  3901.   WPOINTER w1,w2,w3;
  3902.  
  3903.   main()
  3904.   {
  3905.     WindowInitializeSystem();
  3906.     WindowSaveInitial(0);
  3907.  
  3908.     /* Initialize all windows */
  3909.     w1 = WindowInitialize(BORDER,1,1,20,10,NORM,NORM,SINGLEBOX);
  3910.     w2 = WindowInitialize(BORDER,2,2,20,10,REDONWHITE,NORM,DOUBLEBOX);
  3911.     w3 = WindowInitialize(BORDER,3,3,20,10,BLACKONWHITE,NORM,SINGLEBOX);
  3912.  
  3913.     /* Open all windows */
  3914.     WindowOpen(w1);
  3915.     WindowOpen(w2);
  3916.     WindowOpen(w3);
  3917.  
  3918.     /* Display All windows */
  3919.     WindowDisplay(w1,1,NOEFFECT);
  3920.     WindowDisplay(w2,2,NOEFFECT);
  3921.     WindowDisplay(w3,3,NOEFFECT);
  3922.  
  3923.  
  3924.  
  3925.  
  3926.  Page 59                     The C Window Library                    Page 59
  3927.  
  3928.     WindowWriteString(w1,"This is window 1",1,1);
  3929.     WindowWriteString(w2,"This is window 2",2,1);
  3930.     WindowWriteString(w3,"This is window 3",3,1);
  3931.  
  3932.     GET_KEY();
  3933.     WindowHide(w3,NOEFFECT);
  3934.     GET_KEY();
  3935.     WindowHide(w2,BRICKS);
  3936.     GET_KEY();
  3937.     WindowHide(w1,CONTRACT);
  3938.   }
  3939.  
  3940.  
  3941.   The example initializes, opens, and displays three windows.  Note that you
  3942.   can hide windows regardless of the order in which they were displayed.  This
  3943.   makes for very flexible window management.
  3944.  
  3945.   If there is no error, WindowHide() returns NO_ERROR.
  3946.  
  3947.   The only error that can occur is if the WPOINTER w does not exist.
  3948.   WindowHide() returns BAD_WINDOW if this is the case.
  3949.  
  3950.  
  3951.  
  3952.  
  3953.  
  3954.  
  3955.  
  3956.  
  3957.  
  3958.  
  3959.  
  3960.  
  3961.  
  3962.  
  3963.  
  3964.  
  3965.  
  3966.  
  3967.  
  3968.  
  3969.  
  3970.  
  3971.  
  3972.  
  3973.  
  3974.  
  3975.  
  3976.  
  3977.  
  3978.  
  3979.  
  3980.  
  3981.  
  3982.  Page 60                     The C Window Library                    Page 60
  3983.  
  3984.                           CREATING COPIES OF A WINDOW
  3985.                           ---------------------------
  3986.  
  3987.   You can create copies of a window without going through the
  3988.   WindowInitialize(), WindowOpen(), etc. cycle.
  3989.  
  3990.  
  3991.   WindowCopy()
  3992.   ------------
  3993.  
  3994.   The WindowCopy() function makes a copy of a previous window.  The copy
  3995.   will have the same colors, border type, shadow, and may have the same text as
  3996.   a previous window.  If the original window is a viewport on a virtual window
  3997.   (virtual windows are discussed later in the VIRTUAL WINDOWS section), the
  3998.   copy can also be made a viewport on the same virtual window.  The only thing
  3999.   that will not be copied is the (row,col) of the original window.  You supply
  4000.   the position of the new window.  Here is the prototype:
  4001.  
  4002.           WPOINTER WindowCopy(WPOINTER w, int row, int col, int options)
  4003.  
  4004.   Please note that WindowCopy() returns a new WPOINTER.  You must assign the
  4005.   return value to a WPOINTER or you will not get easy access to the newly
  4006.   created window.
  4007.  
  4008.   The first argument is the original window to copy.  This window must already
  4009.   exist.  The second and third arguments are the coordinates of where to place
  4010.   the new window.  The last argument are additional options that control
  4011.   whether the window will contain the same text as the previous window, and if
  4012.   the new window will be made a viewport if the original window is a viewport.
  4013.   The constants used for options is as follows:
  4014.  
  4015.   options             action
  4016.   -------             ------
  4017.  
  4018.   COPYTEXT            Makes a copy of the text area of the original window.
  4019.  
  4020.   MAKEVIEWPORT        Turns the copy into a viewport if the original is a
  4021.                       viewport.
  4022.  
  4023.   NO_OPTIONS          No options desired.
  4024.  
  4025.  
  4026.   As was stated before, viewports are discussed in the VIRTUAL WINDOW section
  4027.   of the manual.  If options is NO_OPTIONS, the windows size, border type,
  4028. shadow (if there is a shadow) and colors are copied.
  4029.  
  4030.  
  4031.  
  4032.  
  4033.  
  4034.  
  4035.  
  4036.  
  4037.  
  4038.  Page 61                     The C Window Library                    Page 61
  4039.  
  4040.   Example:
  4041.  
  4042.   #include "window.h"
  4043.  
  4044.   #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  4045.  
  4046.   WPOINTER w,w2;
  4047.  
  4048.   main()
  4049.   {
  4050.     WindowInitializeSystem();
  4051.     WindowSaveInitial(0);
  4052.     w = WindowInitialize(BORDER,1,1,45,10,NORM,NORM,SINGLEBOX);
  4053.     WindowOpen(w);
  4054.     WindowDisplay(w,1,NOEFFECT);
  4055.     WindowWriteString(w,"This will be copied to the new window",1,1);
  4056.     GET_KEY();
  4057.     w2 = WindowCopy(w,3,3,COPYTEXT);  /* Make a copy of w */
  4058.     WindowDisplay(w2,1,NOEFFECT);     /* Display this copy */
  4059.     GETKEY();
  4060.     WindowFreeAll(0,NOEFFECT);
  4061.   }
  4062.  
  4063.  
  4064.   If there is no error, WindowCopy() returns a valid WPOINTER.
  4065.   If there is an error, WindowCopy() returns a WIN_NULL_PTR (a null window
  4066.   pointer) and sets window_error_code to one of the following values:
  4067.  
  4068.    NO_HEAP_MEM if there is not enough memory to allocate for the window
  4069.    structure.
  4070.  
  4071.    BAD_WINDOW_SIZE if the dimensions for the window are too large for the
  4072.    physical screen.
  4073.  
  4074.    MAX_WINDOW if there are > 254 windows defined.
  4075.  
  4076.  
  4077.  
  4078.  
  4079.  
  4080.  
  4081.  
  4082.  
  4083.  
  4084.  
  4085.  
  4086.  
  4087.  
  4088.  
  4089.  
  4090.  
  4091.  
  4092.  
  4093.  
  4094.  Page 62                     The C Window Library                    Page 62
  4095.  
  4096.                            SCROLLING TEXT IN WINDOWS
  4097.                            -------------------------
  4098.  
  4099.   With The C Window Library, you can scroll text in a window up, or down, or
  4100.   scroll just particular regions of a window.  The functions used to scroll
  4101.   windows are WindowScroll(), WindowScrollAttr(), WindowScrollRegion(), and
  4102.   WindowScrollRegionAttr().
  4103.  
  4104.   When specifying a direction, use the constant UP to scroll up or DOWN to
  4105.   scroll down.  These constants are defined in window.h.
  4106.  
  4107.  
  4108.  
  4109.   WindowScroll()
  4110.   --------------
  4111.  
  4112.   If you want to scroll the entire window either up or down, you can use the
  4113.   WindowScroll() function.  Here is a prototype:
  4114.  
  4115.     int WindowScroll(WPOINTER w, int numlines, int direction)
  4116.  
  4117.  
  4118.   The first argument is the window to scroll.   The second argument is the
  4119.   number of lines to scroll. The last argument is the direction to scroll the
  4120.   window (either UP or DOWN).
  4121.  
  4122.  
  4123.   Example:
  4124.  
  4125.   #include "window.h"
  4126.   #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  4127.  
  4128.   WPOINTER w;
  4129.  
  4130.   main()
  4131.   {
  4132.     int i;
  4133.     WindowInitializeSystem();
  4134.     WindowSaveInitial(0);
  4135.     w = WindowInitialize(BORDER,1,1,20,10,NORM,NORM,SINGLEBOX);
  4136.     WindowOpen(w);
  4137.     WindowDisplay(w,1,NOEFFECT);
  4138.     for (i=0;i<10;i++)
  4139.       WindowWriteRepeatCharacter(w,'A'+i,i+1,1,20);
  4140.     GET_KEY();
  4141.     WindowScroll(w,1,UP);
  4142.     GET_KEY();
  4143.     WindowScroll(w,3,DOWN);
  4144.   }
  4145.  
  4146.   The above example creates text using WindowWriteRepeatCharacter() function.
  4147.   The WindowScroll() calls will scroll the window up by one line, and then
  4148.   scroll the window down by 3 lines.
  4149.  
  4150.  Page 63                     The C Window Library                    Page 63
  4151.  
  4152.   If there is no error, WindowScroll() returns NO_ERROR.
  4153.   If there is an error, WindowScroll() will return the following values:
  4154.  
  4155.   BAD_WINDOW if the WPOINTER w does not exist.
  4156.  
  4157.   WINDOW_NOT_OPEN if the window was not open for writing (use WindowOpen() to
  4158.   open the window for writing).
  4159.  
  4160.  
  4161.  
  4162.  
  4163.   WindowScrollRegion()
  4164.   --------------------
  4165.  
  4166.   The WindowScrollRegion() functions scrolls a specified region of a window.
  4167.   To use the WindowScrollRegion() function, you must describe the rectangular
  4168.   region to scroll.  Here is the prototype:
  4169.  
  4170.   int WindowScrollRegion(WPOINTER w, int numlines, int urow, int ucol, int lrow,
  4171.                          int lcol, int direction)
  4172.  
  4173.   Arguments 3 thru 6 describe the rectangular region.  They are in the order of
  4174.   upper left row, upper left column, lower right row, lower right column.  All
  4175.   of these coordinates are window relative.  The second argument is the number
  4176.   of lines to scroll.  The last argument is the direction.
  4177.  
  4178.  
  4179.   Example:
  4180.  
  4181.   #include "window.h"
  4182.   #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  4183.  
  4184.   WPOINTER w;
  4185.  
  4186.   main()
  4187.   {
  4188.     int i;
  4189.     WindowInitializeSystem();
  4190.     WindowSaveInitial(0);
  4191.     w = WindowInitialize(BORDER,1,1,20,10,NORM,NORM,SINGLEBOX);
  4192.     WindowOpen(w);
  4193.     WindowDisplay(w,1,NOEFFECT);
  4194.     for (i=0;i<10;i++)
  4195.       WindowWriteRepeatCharacter(w,'A'+i,i+1,1,20);
  4196.     GET_KEY();
  4197.     WindowScrollRegion(w,1,2,2,4,10,UP);
  4198.     GET_KEY();
  4199.     WindowScrollRegion(w,3,7,2,9,8,DOWN);
  4200.   }
  4201.  
  4202.  
  4203.  
  4204.  
  4205.  
  4206.  Page 64                     The C Window Library                    Page 64
  4207.  
  4208.   The above example creates text using WindowWriteRepeatCharacter() function.
  4209.   The first WindowScrollRegion() call will scroll the region described by
  4210.   the rectangular coordinates (2,2) and (4,10).  This region is scrolled up one
  4211.   line.  The second call to WindowScrollRegion() scrolls the region defined by
  4212.   the rectangular region (7,2) and (9,8).  This region is scrolled down by
  4213.   three lines.
  4214.  
  4215.   If there is no error, WindowScrollRegion() returns NO_ERROR.
  4216.  
  4217.   If there is an error, the WindowScrollRegion() function will return of the
  4218.   following values:
  4219.  
  4220.   BAD_WINDOW if the WPOINTER w does not exist.
  4221.  
  4222.   WINDOW_BOUND if the rectangular region defined is out of bounds of the
  4223.   window.
  4224.  
  4225.   WINDOW_NOT_OPEN if the window was not open for writing (use WindowOpen() to
  4226.   open the window for writing).
  4227.  
  4228.  
  4229.  
  4230.  
  4231.   WindowScrollAttr()
  4232.   ------------------
  4233.   This function works the same way as the WindowScroll() function except that
  4234.   an attribute is defined for the blank lines that are created when the window
  4235.   is scrolled.  Here is a prototype:
  4236.  
  4237.   int WindowScrollAttr(WPOINTER w, int numlines, int direction, int attr)
  4238.  
  4239.   The last argument is the attribute to use for the blank lines created.
  4240.  
  4241.   Example:
  4242.  
  4243.   #include "window.h"
  4244.   #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  4245.   #define REDONWHITE  CREATE_VIDEO_ATTRIBUTE(red,white)
  4246.  
  4247.   WPOINTER w;
  4248.  
  4249.   main()
  4250.   {
  4251.     int i;
  4252.     WindowInitializeSystem();
  4253.     WindowSaveInitial(0);
  4254.     w = WindowInitialize(BORDER,1,1,20,10,NORM,NORM,SINGLEBOX);
  4255.     WindowOpen(w);
  4256.     WindowDisplay(w,1,NOEFFECT);
  4257.     for (i=0;i<10;i++)
  4258.       WindowWriteRepeatCharacter(w,'A'+i,i+1,1,20);
  4259.     GET_KEY();
  4260.  
  4261.  
  4262.  Page 65                     The C Window Library                    Page 65
  4263.  
  4264.     WindowScrollAttr(w,1,UP,REDONWHITE);
  4265.     GET_KEY();
  4266.     WindowScrollAttr(w,3,DOWN,REDONWHITE);
  4267.   }
  4268.  
  4269.   The above example creates text using WindowWriteRepeatCharacter() function.
  4270.   The WindowScrollAttr() calls will scroll the window up by one line, and then
  4271.   scroll the window down by 3 lines with both scrolls using REDONWHITE as the
  4272.   video attribute.
  4273.  
  4274.   WindowScrollAttr() returns the same values as WindowScroll().
  4275.  
  4276.  
  4277.  
  4278.  
  4279.   WindowScrollRegionAttr()
  4280.   ------------------------
  4281.  
  4282.   This function works the same way as the WindowScrollRegion() function
  4283.   except that an attribute is defined for the blank lines that are created when
  4284.   the window is scrolled.  Here is a prototype:
  4285.  
  4286.   int WindowScrollRegionAttr(WPOINTER w, int numlines, int urow, int ucol,
  4287.                             int lrow, int lcol,int direction, int attr)
  4288.  
  4289.   The last argument is the attribute to use for the blank lines created.
  4290.  
  4291.  
  4292.   Example:
  4293.  
  4294.   #include "window.h"
  4295.   #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  4296.   #define REDONWHITE  CREATE_VIDEO_ATTRIBUTE(red,white)
  4297.  
  4298.   WPOINTER w;
  4299.  
  4300.   main()
  4301.   {
  4302.     int i;
  4303.     WindowInitializeSystem();
  4304.     WindowSaveInitial(0);
  4305.     w = WindowInitialize(BORDER,1,1,20,10,NORM,NORM,SINGLEBOX);
  4306.     WindowOpen(w);
  4307.     WindowDisplay(w,1,NOEFFECT);
  4308.     for (i=0;i<10;i++)
  4309.       WindowWriteRepeatCharacter(w,'A'+i,i+1,1,20);
  4310.     GET_KEY();
  4311.     WindowScrollRegionAttr(w,1,3,5,6,15,UP,REDONWHITE);
  4312.     GET_KEY();
  4313.     WindowScrollRegionAttr(w,3,8,4,10,12,DOWN,REDONWHITE);
  4314.   }
  4315.  
  4316.  
  4317.  
  4318.  Page 66                     The C Window Library                    Page 66
  4319.  
  4320.   The above example creates text using WindowWriteRepeatCharacter() function.
  4321.   The first WindowScrollRegionAttr() call will scroll the region described by
  4322.   the rectangular coordinates (2,2) and (4,10).  This region is scrolled one
  4323.   line.  The second call to WindowScrollRegionAttr() scrolls the region defined
  4324.   by the rectangular region (7,2) and (9,8).  This region is scrolled down by
  4325.   three lines.  All blank lines use the video attribute REDONWHITE.
  4326.  
  4327.   WindowScrollRegionAttr() returns the same values as WindowScrollRegion().
  4328.  
  4329.  
  4330.  
  4331.  
  4332.  
  4333.  
  4334.  
  4335.  
  4336.  
  4337.  
  4338.  
  4339.  
  4340.  
  4341.  
  4342.  
  4343.  
  4344.  
  4345.  
  4346.  
  4347.  
  4348.  
  4349.  
  4350.  
  4351.  
  4352.  
  4353.  
  4354.  
  4355.  
  4356.  
  4357.  
  4358.  
  4359.  
  4360.  
  4361.  
  4362.  
  4363.  
  4364.  
  4365.  
  4366.  
  4367.  
  4368.  
  4369.  
  4370.  
  4371.  
  4372.  
  4373.  
  4374.  Page 67                     The C Window Library                    Page 67
  4375.  
  4376.                                CLEARING WINDOWS
  4377.                                ----------------
  4378.  
  4379.   The C Window Library contains functions that clears the entire window, or
  4380.   clears defined rectangular regions of the window.
  4381.  
  4382.  
  4383.   WindowClear()
  4384.   -------------
  4385.  
  4386.   The WindowClear() function clears an entire window to spaces.  The attribute
  4387.   used is the current attribute of the text area of the window.  Here is the
  4388.   prototype:
  4389.  
  4390.                  int WindowClear(WPOINTER w)
  4391.  
  4392.   The only argument is the window to clear.
  4393.  
  4394.   Example:
  4395.  
  4396.   #include "window.h"
  4397.   #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  4398.  
  4399.   WPOINTER w;
  4400.  
  4401.   main()
  4402.   {
  4403.     int i;
  4404.     WindowInitializeSystem();
  4405.     WindowSaveInitial(0);
  4406.     w = WindowInitialize(BORDER,1,1,20,10,NORM,NORM,SINGLEBOX);
  4407.     WindowOpen(w);
  4408.     WindowDisplay(w,1,NOEFFECT);
  4409.     for (i=1;i<=10;i++)
  4410.       WindowWriteString(w,"Hello World!!",i,1);
  4411.     GET_KEY();
  4412.     WindowClear(w);
  4413.   }
  4414.  
  4415.   If there is no error, WindowClear() returns NO_ERROR.
  4416.  
  4417.   If there is an error, WindowClear() returns the following values:
  4418.  
  4419.   BAD_WINDOW if the WPOINTER w does not exist.
  4420.  
  4421.   WINDOW_NOT_OPEN if the window is not open for writing (use WindowOpen() to
  4422.   open the window for writing).
  4423.  
  4424.  
  4425.  
  4426.  
  4427.  
  4428.  
  4429.  
  4430.  Page 68                     The C Window Library                    Page 68
  4431.  
  4432.   WindowClearAttr()
  4433.   -----------------
  4434.  
  4435.   The WindowClearAttr() function works the same way as the WindowClear()
  4436.   function except that an attribute is specified.  Here is the prototype:
  4437.  
  4438.      int WindowClearAttr(WPOINTER w, int attr)
  4439.  
  4440.   The second argument is the video attribute to use.
  4441.  
  4442.  
  4443.   Example:
  4444.  
  4445.   #include "window.h"
  4446.   #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  4447.   #define REDONWHITE  CREATE_VIDEO_ATTRIBUTE(red,white)
  4448.  
  4449.   WPOINTER w;
  4450.  
  4451.   main()
  4452.   {
  4453.     int i;
  4454.     WindowInitializeSystem();
  4455.     WindowSaveInitial(0);
  4456.     w = WindowInitialize(BORDER,1,1,20,10,NORM,NORM,SINGLEBOX);
  4457.     WindowOpen(w);
  4458.     WindowDisplay(w,1,NOEFFECT);
  4459.     for (i=1;i<=10;i++)
  4460.       WindowWriteString(w,"Hello World!!",i,1);
  4461.     GET_KEY();
  4462.     WindowClearAttr(w,REDONWHITE);
  4463.   }
  4464.  
  4465.   The return values for WindowClearAttr() are the same as WindowClear().
  4466.  
  4467.  
  4468.  
  4469.  
  4470.  
  4471.   WindowClearRegion()
  4472.   -------------------
  4473.  
  4474.   The WindowClearRegion() function clears a region of a window.  To use the
  4475.   WindowClearRegion() function, you must describe the rectangular region to
  4476.   clear.  Here is the prototype:
  4477.  
  4478.   int WindowClearRegion(WPOINTER w, int urow, int ucol, int lrow, int lcol)
  4479.  
  4480.   where (urow,ucol) describes the upper left of the rectangle and (lrow,lcol)
  4481.   is the lower right of the window.  These coordinates are window relative.
  4482.  
  4483.  
  4484.  
  4485.  
  4486.  Page 69                     The C Window Library                    Page 69
  4487.  
  4488.   Example:
  4489.  
  4490.   #include "window.h"
  4491.   #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  4492.  
  4493.   WPOINTER w;
  4494.  
  4495.   main()
  4496.   {
  4497.     int i;
  4498.     WindowInitializeSystem();
  4499.     WindowSaveInitial(0);
  4500.     w = WindowInitialize(BORDER,1,1,20,10,NORM,NORM,SINGLEBOX);
  4501.     WindowOpen(w);
  4502.     WindowDisplay(w,1,NOEFFECT);
  4503.     for (i=1;i<=10;i++)
  4504.       WindowWriteString(w,"Hello World!!",i,1);
  4505.     GET_KEY();
  4506.     WindowClearRegion(w,4,4,8,15);
  4507.   }
  4508.  
  4509.  
  4510.   The WindowClearRegion() call will clear the region described by the
  4511.   rectangular coordinates (4,4) and (8,15).
  4512.  
  4513.   If there is no error, WindowClearRegion() returns NO_ERROR.
  4514.  
  4515.   If there is an error, the WindowClearRegion() function will return the
  4516.   following values:
  4517.  
  4518.   BAD_WINDOW if the WPOINTER w does not exist.
  4519.  
  4520.   WINDOW_BOUND if the rectangular region defined is out of bounds of the
  4521.   window.
  4522.  
  4523.   WINDOW_NOT_OPEN if the window is not open for writing (use WindowOpen() to
  4524.   open the window for writing).
  4525.  
  4526.  
  4527.  
  4528.  
  4529.  
  4530.   WindowClearRegionAttr()
  4531.   -----------------------
  4532.  
  4533.   The WindowClearRegionAttr() function works the same as the
  4534.   WindowClearRegion() function, except that a video attribute is specified.
  4535.   Here is the prototype:
  4536.  
  4537.   int WindowClearRegionAttr(WPOINTER w, int urow, int ucol, int lrow, int lcol,
  4538.                             int attr)
  4539.  
  4540.   The attr argument is a video attribute to use to clear the region.
  4541.  
  4542.  Page 70                     The C Window Library                    Page 70
  4543.  
  4544.   Example:
  4545.  
  4546.   #include "window.h"
  4547.   #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  4548.   #define REDONWHITE  CREATE_VIDEO_ATTRIBUTE(red,white)
  4549.  
  4550.   WPOINTER w;
  4551.  
  4552.   main()
  4553.   {
  4554.     int i;
  4555.     WindowInitializeSystem();
  4556.     WindowSaveInitial(0);
  4557.     w = WindowInitialize(BORDER,1,1,20,10,NORM,NORM,SINGLEBOX);
  4558.     WindowOpen(w);
  4559.     WindowDisplay(w,1,NOEFFECT);
  4560.     for (i=1;i<=10;i++)
  4561.       WindowWriteString(w,"Hello World!!",i,1);
  4562.     GET_KEY();
  4563.     WindowClearRegionAttr(w,4,4,8,15,REDONWHITE);
  4564.   }
  4565.  
  4566.  
  4567.   The WindowClearRegionAttr() call will clear the region described by the
  4568.   rectangular coordinates (4,4) and (8,15) using the video attribute defined
  4569.   by the constant REDONWHITE.
  4570.  
  4571.   The WindowClearRegionAttr() returns the same values as WindowClearRegion().
  4572.  
  4573.  
  4574.  
  4575.  
  4576.  
  4577.  
  4578.  
  4579.  
  4580.  
  4581.  
  4582.  
  4583.  
  4584.  
  4585.  
  4586.  
  4587.  
  4588.  
  4589.  
  4590.  
  4591.  
  4592.  
  4593.  
  4594.  
  4595.  
  4596.  
  4597.  
  4598.  Page 71                     The C Window Library                    Page 71
  4599.  
  4600.                        WRITING WINDOW CONTENTS TO A FILE
  4601.                        ---------------------------------
  4602.  
  4603.   The C Window Library allows you to print the contents of a window using the
  4604.   WindowWriteTextToFile() function.
  4605.  
  4606.  
  4607.   WindowWriteTextToFile()
  4608.   -----------------------
  4609.  
  4610.   The WindowWriteTextToFile() function allows you to print the contents of a
  4611.   window to a file.  Here is the prototype:
  4612.  
  4613.   int WindowWriteTextToFile(WPOINTER w, char *filename, int mode)
  4614.  
  4615.  
  4616.   The first argument is the window.  The second argument is the file name.
  4617.   This file can be any of the DOS filenames ("con", "prn", "aux", etc.).
  4618.   The file specified by filename must be closed before calling
  4619.   WindowWriteTextToFile(), and the file handle is automatically closed before
  4620.   exiting WindowWriteTextToFile().
  4621.  
  4622.   The last argument is the mode switch.  If mode is 1, a newline ('\n') is
  4623.   written to the file after each line of the window is written to the file.  If
  4624.   mode is 0, no newline character is written.
  4625.  
  4626.  
  4627.  
  4628.   Example:
  4629.  
  4630.   #include "window.h"
  4631.   #include <stdio.h>
  4632.   #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  4633.  
  4634.   WPOINTER w;
  4635.   FILE *outfile;
  4636.   char *filename = "wintext";
  4637.   char *filename2 = "wintext2";
  4638.  
  4639.   main()
  4640.   {
  4641.     int i;
  4642.     WindowInitializeSystem();
  4643.     WindowSaveInitial(0);
  4644.     w = WindowInitialize(BORDER,1,1,20,10,NORM,NORM,SINGLEBOX);
  4645.     WindowOpen(w);
  4646.     WindowDisplay(w,1,NOEFFECT);
  4647.     for (i=1;i<=10;i++)
  4648.       WindowWriteString(w,"Hello World!!",i,1);
  4649.     GET_KEY();
  4650.     WindowWriteTextToFile(w,filename,1);  /* use newlines */
  4651.     WindowWriteTextToFile(w,filename2,0); /* no newlines */
  4652.   }
  4653.  
  4654.  Page 72                     The C Window Library                    Page 72
  4655.  
  4656.   The example above illustrates two calls to WindowWriteTextToFile().  The
  4657.   first call writes the contents of the window w to a file called "wintext".
  4658.   Note that the mode parameter for the first call is 1.  This will cause '\n'
  4659.   to be written to the file for each line of the window.  The second call
  4660.   writes the window text to a file call "wintest2", with the mode parameter
  4661.   being 0 (no '\n').
  4662.  
  4663.   Please note that WindowWriteTextToFile() does not check if the file already
  4664.   exists, so be careful that you do not replace files that are important to
  4665.   you.
  4666.  
  4667.  
  4668.  
  4669.   If there are no errors, WindowWriteTextToFile() returns NO_ERROR.
  4670.  
  4671.   If there are errors, WindowWriteTextToFile() will return one of the following:
  4672.  
  4673.  
  4674.   BAD_WINDOW if the window does not exist.
  4675.  
  4676.   WINDOW_NOT_OPEN if the window is not open for writing (use WindowOpen())
  4677.  
  4678.   FILE_CANT_OPEN if the file specified by filename cannot be open.
  4679.  
  4680.   FILE_CANT_CLOSE if the file specified by filename cannot be closed.
  4681.  
  4682.  
  4683.  
  4684.  
  4685.  
  4686.  
  4687.  
  4688.  
  4689.  
  4690.  
  4691.  
  4692.  
  4693.  
  4694.  
  4695.  
  4696.  
  4697.  
  4698.  
  4699.  
  4700.  
  4701.  
  4702.  
  4703.  
  4704.  
  4705.  
  4706.  
  4707.  
  4708.  
  4709.  
  4710.  Page 73                     The C Window Library                    Page 73
  4711.  
  4712.                                SHADOWING WINDOWS
  4713.                                -----------------
  4714.  
  4715.   With The C Window Library, you can place shadows on the windows created.
  4716.   Shadows create a nice effect when displayed with the proper background color.
  4717.   There are four positions where you can place a shadow on a window: the upper
  4718.   left corner of the window, the upper right corner, the lower left corner or
  4719.   the lower right corner.
  4720.  
  4721.   The shadow consists of two components.  One of these components is the part of
  4722.   the shadow that is drawn either on the left or right side of the window.  You
  4723.   can control the width of this portion of the shadow.  The other component that
  4724.   makes up the shadow is the portion that is drawn either on top of or
  4725.   underneath a window.  You can control the height of this portion of the
  4726.   shadow.
  4727.  
  4728.   You can also control the shadows video attribute, as well as the character
  4729.   that makes up the shadow itself.  My suggestion is to use ASCII character 219
  4730.   for the shadow character.  Other ones that work well are ASCII 176, 178, and
  4731.   178.
  4732.  
  4733.   Transparent shadows are also supported.
  4734.  
  4735.   You can place a shadow on a window at any time or take it off at any time.
  4736.   The only restriction with the shadow is that the window's current position
  4737.   must have room to draw the shadow.
  4738.  
  4739.  
  4740.   WindowDrawShadow()
  4741.   ------------------
  4742.  
  4743.   The WindowDrawShadow() function places a shadow on a window.  Here is the
  4744.   prototype:
  4745.  
  4746.     int WindowDrawShadow(WPOINTER w, int shadowpos, int width, int height, int
  4747.                          shadowchar, int shadowattr, int transflag)
  4748.  
  4749.   The first argument is the window that the shadow will be drawn.  The second
  4750.   argument is the position of the shadow.  There are four possible positions:
  4751.  
  4752.          SHADOWUPRIGHT - draws shadow on upper right corner of the window.
  4753.          SHADOWUPLEFT -  draws shadow on upper left corner of the window.
  4754.          SHADOWLOWRIGHT - draws shadow on lower right corner of window.
  4755.          SHADOWLOWLEFT - draws shadow on lower left corner of window.
  4756.  
  4757.   The third argument is the width of the strip of the shadow that is drawn on
  4758.   the right or left side of the window.  The fourth argument is the height of
  4759.   the strip of the shadow that is drawn on top or underneath the window.  The
  4760.   fifth argument is the character to use for the shadow.  The sixth argument is
  4761.   the attribute to use for the shadow.  The last argument is a flag denoting
  4762.   whether the shadow should be a transparent shadow.  If the flag is 0, the
  4763.   shadow is solid, otherwise the shadow is transparent.
  4764.  
  4765.  
  4766.  Page 74                     The C Window Library                    Page 74
  4767.  
  4768.   Example:
  4769.  
  4770.     #include "window.h"
  4771.     #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)  /* define normal video
  4772.                                                            attribute */
  4773.     #define BLUEONBLACK  CREATE_VIDEO_ATTRIBUTE(black,blue) /* define a
  4774.                                                               blue on black
  4775.                                                              video attribute */
  4776.     #define REDONBLACK   CREATE_VIDEO_ATTRIBUTE(black,red)
  4777.     #define GREENONBLACK CREATE_VIDEO_ATTRIBUTE(black,green)
  4778.     #define REVERSE      CREATE_VIDEO_ATTRIBUTE(white,black)
  4779.  
  4780.     main()
  4781.     {
  4782.       WPOINTER w0,w1;               /* pointers to a window structures */
  4783.       WindowInitializeSystem();     /* system initialization function */
  4784.       WindowSaveInitial(0);
  4785.       w0 = WindowInitialize(NOBORDER,1,1,80,25,REVERSE,REVERSE,0);
  4786.       WindowOpen(w0);
  4787.       WindowDisplay(w0,1,NOEFFECT);
  4788.       w1 = WindowInitialize(BORDER,5,5,40,15,BLUEONBLACK,REDONBLACK,SINGLEBOX);
  4789.       WindowOpen(w1);
  4790.       WindowDrawShadow(w1,SHADOWUPLEFT,2,1,219,REVERSE,0);
  4791.       WindowDisplay(w1,1,NOEFFECT);
  4792.       WindowWriteString(w1,"Press a key to move shadow",1,1);
  4793.       GET_KEY();
  4794.       WindowDrawShadow(w1,SHADOWUPRIGHT,2,1,219,REVERSE,0);
  4795.       WindowWriteString(w1,"Press a key again",2,1);
  4796.       GET_KEY();
  4797.       WindowDrawShadow(w1,SHADOWLOWLEFT,2,1,219,REVERSE,0);
  4798.       WindowWriteString(w1,"Press a key once more",3,1);
  4799.       GET_KEY();
  4800.       WindowDrawShadow(w1,SHADOWLOWRIGHT,2,1,219,REVERSE,0);
  4801.       GET_KEY();
  4802.       WindowClose(w1,NOEFFECT);
  4803.       WindowClose(w0,NOEFFECT);
  4804.     }
  4805.  
  4806.   The above example illustrates the use of WindowDrawShadow().
  4807.  
  4808.   If there is no error, WindowDrawShadow() returns NO_ERROR.
  4809.  
  4810.   If there are errors, WindowDrawShadow() returns one of the following:
  4811.  
  4812.   BAD_WINDOW if the window does not exist.
  4813.  
  4814.   WINDOW_BOUND if a shadow could not be drawn because of window location and
  4815.   the height and/or width of the shadow will exceed the screen edges.
  4816.  
  4817.  
  4818.  
  4819.  
  4820.  
  4821.  
  4822.  Page 75                     The C Window Library                    Page 75
  4823.  
  4824.   WindowRemoveShadow()
  4825.   --------------------
  4826.  
  4827.   The WindowRemoveShadow() function removes a shadow from a window, and takes
  4828.   a single argument, namely the window pointer.  Here is the prototype:
  4829.  
  4830.                    int WindowRemoveShadow(WPOINTER w)
  4831.  
  4832.   If there are no errors or the window does not have a shadow,
  4833.   WindowRemoveShadow() returns NO_ERROR.
  4834.  
  4835.   If there are errors, WindowRemoveShadow() returns the following value:
  4836.  
  4837.   BAD_WINDOW if the window does not exist.
  4838.  
  4839.  
  4840.  
  4841.  
  4842.  
  4843.  
  4844.  
  4845.  
  4846.  
  4847.  
  4848.  
  4849.  
  4850.  
  4851.  
  4852.  
  4853.  
  4854.  
  4855.  
  4856.  
  4857.  
  4858.  
  4859.  
  4860.  
  4861.  
  4862.  
  4863.  
  4864.  
  4865.  
  4866.  
  4867.  
  4868.  
  4869.  
  4870.  
  4871.  
  4872.  
  4873.  
  4874.  
  4875.  
  4876.  
  4877.  
  4878.  Page 76                     The C Window Library                    Page 76
  4879.  
  4880.                                SEE-THRU WINDOWS
  4881.                                ----------------
  4882.  
  4883.   You can create windows that have borders, but do not overwrite the screen
  4884.   underneath.  These windows are called see-thru windows.
  4885.  
  4886.   When creating see-thru windows the WindowMakeSeeThru() function is used to
  4887.   make a defined window a see-thru window.
  4888.  
  4889.   You can turn a non-seethru window into a seethru window and vice-versa by
  4890.   calling the WindowMakeNormal() function.
  4891.  
  4892.  
  4893.  
  4894.   WindowMakeSeeThru()
  4895.   -------------------
  4896.  
  4897.   The WindowMakeSeeThru() function turns a normal window into a see-thru
  4898.   window.  Here is a prototype:
  4899.  
  4900.                     int WindowMakeSeeThru(WPOINTER w)
  4901.  
  4902.   The only argument is the window pointer.  You can make a window a see-thru
  4903.   window at any time, including if it is hidden.  If there is text in the
  4904.   normal window before making it a see-thru window, the text is retained.  If
  4905.   text is written to a see-thru window, the text is written to the window's
  4906.   internal write buffer, but is not displayed on the screen.
  4907.  
  4908.  
  4909.   Example:
  4910.  
  4911.     #include "window.h"
  4912.  
  4913.     #define NORM            CREATE_VIDEO_ATTRIBUTE(black,white)
  4914.  
  4915.     WPOINTER w;
  4916.  
  4917.     main()
  4918.     {
  4919.       WindowInitializeSystem();
  4920.       WindowSaveInitial(0);
  4921.       w = WindowInitialize(BORDER,1,1,20,5,NORM,NORM,SINGLEBOX);
  4922.       WindowOpen(w);
  4923.       WindowDisplay(w,1,NOEFFECT);
  4924.       GET_KEY();
  4925.       WindowMakeSeeThru(w);
  4926.       GET_KEY();
  4927.       WindowFree(w,NOEFFECT);
  4928.     }
  4929.  
  4930.  
  4931.  
  4932.  
  4933.  
  4934.  Page 77                     The C Window Library                    Page 77
  4935.  
  4936.   The example above displays a normal window, and then turns the normal window
  4937.   into a see-thru window when a key is pressed.
  4938.  
  4939.   If there are no errors, WindowMakeSeeThru() returns NO_ERROR.
  4940.  
  4941.   If there are errors, WindowMakeSeeThru() returns the following value:
  4942.  
  4943.   BAD_WINDOW if the window does not exist.
  4944.  
  4945.  
  4946.  
  4947.  
  4948.   WindowMakeNormal()
  4949.   ------------------
  4950.  
  4951.   The WindowMakeNormal() function turns a see-thru window into a normal text
  4952.   window.  Any text that may have been written to the window will be displayed.
  4953.   Here is the prototype:
  4954.  
  4955.                 int WindowMakeNormal(WPOINTER w)
  4956.  
  4957.   Example:
  4958.  
  4959.     #include "window.h"
  4960.  
  4961.     #define NORM            CREATE_VIDEO_ATTRIBUTE(black,white)
  4962.  
  4963.     WPOINTER w;
  4964.  
  4965.     main()
  4966.     {
  4967.       WindowInitializeSystem();
  4968.       WindowSaveInitial(0);
  4969.       w = WindowInitialize(BORDER,1,1,20,5,NORM,NORM,SINGLEBOX);
  4970.       WindowOpen(w);
  4971.       WindowDisplay(w,1,NOEFFECT);
  4972.       GET_KEY();
  4973.       WindowMakeSeeThru(w);
  4974.       GET_KEY();
  4975.       WindowMakeNormal(w);
  4976.     }
  4977.  
  4978.  
  4979.   The example above demonstrates the WindowMakeNormal() function.
  4980.  
  4981.   If there are no errors, WindowMakeNormal() returns NO_ERROR.
  4982.  
  4983.   If there are errors, WindowMakeNormal() returns the following value:
  4984.  
  4985.   BAD_WINDOW if the window does not exist.
  4986.  
  4987.  
  4988.  
  4989.  
  4990.  Page 78                     The C Window Library                    Page 78
  4991.  
  4992.                           MOVING AND SLIDING WINDOWS
  4993.                           --------------------------
  4994.  
  4995.   With The C Window Library, you can move and slide windows on the screen.  The
  4996.   functions that perform this are the WindowMove() and WindowSlide().
  4997.  
  4998.  
  4999.   WindowMove()
  5000.   ------------
  5001.  
  5002.   The WindowMove() function moves a window to a new location on the screen.
  5003.   Here is the prototype:
  5004.  
  5005.                  int WindowMove(WPOINTER w, int row, int col)
  5006.  
  5007.   The first argument is the window.  The second and third arguments are the
  5008.   row and column on the physical screen to place the upper left hand corner of
  5009.   the window.  Note that row and column are screen relative coordinates, not
  5010.   window relative.  This is one of the few functions where row and column
  5011.   denote a screen relative coordinate and not a window relative coordinate.
  5012.  
  5013.   If the row and/or column is out of bounds, the window is moved as far as
  5014.   possible.
  5015.  
  5016.    Example:
  5017.  
  5018.    #include "window.h"
  5019.    #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)  /* define  video
  5020.                                                           attribute */
  5021.    #define BLUEONBLACK  CREATE_VIDEO_ATTRIBUTE(black,blue)  /* define
  5022.                                                            video attribute */
  5023.    main()
  5024.    {
  5025.      WPOINTER w;             /* pointer to a window structure */
  5026.      WindowInitializeSystem();     /* system initialization function */
  5027.      WindowSaveInitial(0);
  5028.      w = WindowInitialize(BORDER,1,1,30,15,BLUEONBLACK,NORM,SINGLEBOX);
  5029.      WindowOpen(w);              /* display window on the screen */
  5030.      WindowWriteString(w,"Press a key to move me",1,1);
  5031.      WindowDisplay(w,1,NOEFFECT);
  5032.      GET_KEY();
  5033.      WindowMove(w,12,14);       /* move the window to row 12, column 14 of the
  5034.                                 screen */
  5035.    }
  5036.  
  5037.   The example above moves the window from its original position (1,1) to
  5038.   (12,14).
  5039.  
  5040.   If there is no error WindowMove() returns NO_ERROR.
  5041.  
  5042.   If there are errors WindowMove() returns the following value:
  5043.  
  5044.   BAD_WINDOW if the window does not exist.
  5045.  
  5046.  Page 79                     The C Window Library                    Page 79
  5047.  
  5048.   WindowSlide()
  5049.   -------------
  5050.  
  5051.   The WindowSlide() function "slides" a window from one position on the screen
  5052.   to another.  Here is the prototype:
  5053.  
  5054.       int WindowSlide(WPOINTER w, int direction, int units)
  5055.  
  5056.   The first argument is the window.  The second argument tells in which
  5057.   direction to move the window, either up, down, left, or right.  The
  5058.   constants to use for up, down, left, and right are UP, DOWN, LEFT, and
  5059.   RIGHT, respectively.  The third argument tells how many rows or columns to
  5060.   move the window.  If the number of units will cause the window to exceed the
  5061.   boundaries of the screen, the window is moved as far as possible.
  5062.  
  5063.  
  5064.   Example:
  5065.  
  5066.    #include "window.h"
  5067.    #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)  /* define  video
  5068.                                                           attribute */
  5069.    #define BLUEONBLACK  CREATE_VIDEO_ATTRIBUTE(black,blue)  /* define
  5070.                                                            video attribute */
  5071.  
  5072.    main()
  5073.    {
  5074.      WPOINTER w;             /* pointer to a window structure */
  5075.      WindowInitializeSystem();     /* system initialization function */
  5076.      WindowSaveInitial(0);
  5077.      w = WindowInitialize(BORDER,1,1,30,10,BLUEONBLACK,NORM,SINGLEBOX);
  5078.      WindowOpen(w);              /* display window on the screen */
  5079.      WindowWriteString(w,"Press a key to slide right",1,1);
  5080.      WindowDisplay(w,1,NOEFFECT);
  5081.      GET_KEY();
  5082.      WindowSlide(w,RIGHT,20);
  5083.      WindowWriteString(w,"Press a key to slide down",2,1);
  5084.      GET_KEY();
  5085.      WindowSlide(w,DOWN,10);
  5086.      WindowWriteString(w,"Press a key to slide left",3,1);
  5087.      GET_KEY();
  5088.      WindowSlide(w,LEFT,20);
  5089.      WindowWriteString(w,"Press a key to slide up",4,1);
  5090.      GET_KEY();
  5091.      WindowSlide(w,UP,20);
  5092.    }
  5093.  
  5094.  
  5095.    The example above illustrates how to use the WindowSlide() function.
  5096.  
  5097.    The return values for WindowSlide() are the same as WindowMove().
  5098.  
  5099.  
  5100.  
  5101.  
  5102.  Page 80                     The C Window Library                    Page 80
  5103.  
  5104.                          CURSOR POSITIONING IN WINDOWS
  5105.                          -----------------------------
  5106.  
  5107.   You can change the position of the cursor and its shape in the windows you
  5108.   create with The C Window Library.
  5109.  
  5110.  
  5111.  
  5112.   Cursor Maintenance in The C Window Library
  5113.   ------------------------------------------
  5114.  
  5115.   As was stated before, The C Window Library can write to any window at any
  5116.   time.  This makes the question "which window owns the cursor?" a hard
  5117.   question to answer.  One method is that the window being updated either by
  5118.   writing text, clearing, etc. should have immediate control of the cursor.
  5119.   The approach The C Window Library has taken is that the top-most window
  5120.   always has control of the cursor.  The topmost window is determined by its
  5121.   rank number.  Windows with low rank numbers overlay windows with higher rank
  5122.   numbers.
  5123.  
  5124.  
  5125.  
  5126.   Creating Cursor Shapes
  5127.   ----------------------
  5128.  
  5129.   The C Window Library has three pre-defined cursor shapes; INVISIBLE, THIN,
  5130.   and BLOCK.  An INVISIBLE cursor hides the cursor, a BLOCK shape creates a
  5131.   "fat" cursor, and THIN creates a thin cursor.  If you want to define your own
  5132.   cursor shapes, use the CREATE_CURSOR_SHAPE() macro.  This macro takes two
  5133.   arguments the first argument is the beginning scan line, and the second
  5134.   argument is the ending scan line.  Scan lines determine the height of the
  5135.   cursor.  For monochrome systems, the scan lines range from 0 to 13.  In a
  5136.   color system, the scan lines range from 0 to 7.  A THIN cursor has its
  5137.   starting scan line at 6 and its ending scan line at 7 for color systems, and
  5138.   for monochrome systems, the starting scan line is 11 and its ending scan line
  5139.   is at 12.  If the starting scan line number is greater than the ending scan
  5140.   line number, the cursor takes on a 'double' cursor shape.  Experiment with
  5141.   different starting and ending scan lines for the desired effect.
  5142.  
  5143.  
  5144.  
  5145.   WindowChangeCursor()
  5146.   --------------------
  5147.  
  5148.   The WindowChangeCursor() function changes the shape of the cursor in a
  5149.   window.  Here is the prototype:
  5150.  
  5151.                int WindowChangeCursor(WPOINTER w, int shape)
  5152.  
  5153.   The first argument is the window.  The second argument is the desired cursor
  5154.   shape.
  5155.  
  5156.  
  5157.  
  5158.  Page 81                     The C Window Library                    Page 81
  5159.  
  5160.   Example:
  5161.  
  5162.   #include "window.h"
  5163.   #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  5164.  
  5165.  
  5166.  
  5167.   WPOINTER w;
  5168.  
  5169.   main()
  5170.   {
  5171.     WindowInitializeSystem();
  5172.     WindowSaveInitial(0);
  5173.     w = WindowInitialize(BORDER,1,1,40,10,NORM,NORM,SINGLEBOX);
  5174.     WindowOpen(w);
  5175.     WindowDisplay(w,1,NOEFFECT);
  5176.     WindowWriteString(w,"Press a key to change cursor",1,1);/* Write String */
  5177.     GET_KEY();
  5178.     WindowChangeCursor(w,BLOCK);
  5179.     WindowWriteString(w,"Press a key to change cursor again",2,1);
  5180.     GET_KEY();
  5181.     WindowChangeCursor(w,INVISIBLE);
  5182.     WindowWriteString(w,"Press a key to change cursor again",3,1);
  5183.     GET_KEY();
  5184.     WindowChangeCursor(w,THIN);
  5185.   }
  5186.  
  5187.  
  5188.   If there are no errors, WindowChangeCursor() returns NO_ERROR.
  5189.   If there are errors, WindowChangeCursor() returns the following value:
  5190.  
  5191.   BAD_WINDOW if the window does not exist.
  5192.  
  5193.  
  5194.  
  5195.  
  5196.  
  5197.   WindowMoveCursor()
  5198.   ------------------
  5199.  
  5200.   The WindowMoveCursor() functions moves the cursor in a window to a new
  5201.   location in the window.  Here is the prototype:
  5202.  
  5203.  
  5204.            int WindowMoveCursor(WPOINTER w, int row, int col)
  5205.  
  5206.   The first argument is the window, and the second and third arguments are the
  5207.   new (row,col) position in the window to place the cursor.
  5208.  
  5209.  
  5210.  
  5211.  
  5212.  
  5213.  
  5214.  Page 82                     The C Window Library                    Page 82
  5215.  
  5216.   Example:
  5217.  
  5218.   #include "window.h"
  5219.   #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  5220.  
  5221.   WPOINTER w;
  5222.  
  5223.   main()
  5224.   {
  5225.     WindowInitializeSystem();
  5226.     WindowSaveInitial(0);
  5227.     w = WindowInitialize(BORDER,1,1,40,10,NORM,NORM,SINGLEBOX);
  5228.     WindowOpen(w);
  5229.     WindowDisplay(w,1,NOEFFECT);
  5230.     WindowWriteString(w,"Press a key to move cursor",1,1);/* Write String */
  5231.     GET_KEY();
  5232.     WindowMoveCursor(w,7,5); /* Move Cursor To row 7, column 5 of the window */
  5233.   }
  5234.  
  5235.  
  5236.   If there are no errors, WindowMoveCursor() returns NO_ERROR.
  5237.   If there are errors, WindowMoveCursor() returns the following values:
  5238.  
  5239.   BAD_WINDOW if the window does not exist.
  5240.  
  5241.   WINDOW_BOUND if either new row or column number is out of the boundaries of
  5242.   the window.
  5243.  
  5244.  
  5245.  
  5246.  
  5247.   WindowGetCursorShape()
  5248.   ----------------------
  5249.  
  5250.   The WindowGetCursorShape() function returns the starting and ending scan lines
  5251.   of the cursor defined in a window.  Here is the prototype:
  5252.  
  5253.  
  5254.         int WindowGetCursorShape(WPOINTER w, int *startline, int *endline)
  5255.  
  5256.   The startline and endline arguments are pointers to integers that will
  5257.   contain the starting and ending scan lines of the cursor when
  5258.   WindowGetCursorShape() returns.
  5259.  
  5260.  
  5261.  
  5262.  
  5263.  
  5264.  
  5265.  
  5266.  
  5267.  
  5268.  
  5269.  
  5270.  Page 83                     The C Window Library                    Page 83
  5271.  
  5272.   Example:
  5273.  
  5274.   #include "window.h"
  5275.   #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  5276.  
  5277.   WPOINTER w;
  5278.  
  5279.   main()
  5280.   {
  5281.     int startline,endline;
  5282.     WindowInitializeSystem();
  5283.     WindowSaveInitial(0);
  5284.     w = WindowInitialize(BORDER,1,1,40,10,NORM,NORM,SINGLEBOX);
  5285.     WindowOpen(w);
  5286.     WindowDisplay(w,1,NOEFFECT);
  5287.     WindowGetCursorShape(w,&startline,&endline);
  5288.     WindowPrintf(w,"The starting scan line is %d\nThe ending scan line is %d",
  5289.                  startline,endline);
  5290.   }
  5291.  
  5292.   The example above calls WindowGetCursorShape() and uses WindowPrintf() to
  5293.   print what the starting and ending scan lines are.
  5294.  
  5295.   If there are no errors, WindowGetCursorShape() returns NO_ERROR.
  5296.   If there are errors, WindowGetCursorShape() returns the following values:
  5297.  
  5298.   BAD_WINDOW if the window does not exist.
  5299.  
  5300.  
  5301.  
  5302.  
  5303.  
  5304.   WindowGetCursorPosition()
  5305.   -------------------------
  5306.  
  5307.   The WindowGetCursorPosition() function gives the current row and column of
  5308.   the cursor in a window.  Here is the prototype:
  5309.  
  5310.  
  5311.          int WindowGetCursorPosition(WPOINTER w, int *row, int *col)
  5312.  
  5313.   The row and col arguments are pointers to integers that will contain the row
  5314.   and column of the cursor after WindowGetCursorPosition() is called.
  5315.  
  5316.  
  5317.  
  5318.  
  5319.  
  5320.  
  5321.  
  5322.  
  5323.  
  5324.  
  5325.  
  5326.  Page 84                     The C Window Library                    Page 84
  5327.  
  5328.   Example:
  5329.  
  5330.   #include "window.h"
  5331.   #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  5332.  
  5333.   WPOINTER w;
  5334.  
  5335.   main()
  5336.   {
  5337.     int row,col;
  5338.     WindowInitializeSystem();
  5339.     WindowSaveInitial(0);
  5340.     w = WindowInitialize(BORDER,1,1,40,10,NORM,NORM,SINGLEBOX);
  5341.     WindowOpen(w);
  5342.     WindowDisplay(w,1,NOEFFECT);
  5343.     WindowMoveCursor(w,7,4);
  5344.     WindowGetCursorPosition(w,&row,&col);
  5345.     WindowPrintf(w,
  5346.         "The row of the cursor is %d\nThe column of the cursor is %d",
  5347.          row,col);
  5348.   }
  5349.  
  5350.   If there are no errors, WindowGetCursorPosition() returns NO_ERROR.
  5351.   If there are errors, WindowGetCursorPosition() returns the following value:
  5352.  
  5353.   BAD_WINDOW if the window does not exist.
  5354.  
  5355.  
  5356.  
  5357.  
  5358.  
  5359.  
  5360.  
  5361.  
  5362.  
  5363.  
  5364.  
  5365.  
  5366.  
  5367.  
  5368.  
  5369.  
  5370.  
  5371.  
  5372.  
  5373.  
  5374.  
  5375.  
  5376.  
  5377.  
  5378.  
  5379.  
  5380.  
  5381.  
  5382.  Page 85                     The C Window Library                    Page 85
  5383.  
  5384.                           GETTING INPUT FROM WINDOWS
  5385.                           --------------------------
  5386.  
  5387.   With The C Window Library, you can read input from windows.  The input can be
  5388.   simple string input, or inputting strings with a character mask.  There is
  5389.   also support for scrolling input fields.
  5390.  
  5391.  
  5392.  
  5393.  
  5394.   Input Manager
  5395.   -------------
  5396.  
  5397.   The input manager are functions internal in The C Window Library that control
  5398.   editing, checking for invalid characters, cursor movement, etc.
  5399.  
  5400.  
  5401.   Regular Expressions
  5402.   -------------------
  5403.   With The C Window Library, you specify exactly what characters are to be
  5404.   expected for every input position by using a special string of characters
  5405.   called a regular expression (a pattern matching string).
  5406.  
  5407.   Note:
  5408.   For those who are familiar with regular expressions, there is a difference
  5409.   between the regular expressions you will see here, and the regular
  5410.   expressions you will find in certain text editors, or in computer language
  5411.   syntax definitions.  One major difference is that there are no wild cards
  5412.   denoting an arbitrary number of repeated characters (which is usually denoted
  5413.   by a '*' or a '+'), and there are no 'match begin of string' and 'match end
  5414.   of string' functions.
  5415.  
  5416.  
  5417.  
  5418.   An example of a regular expression would be the string "[A-Z]" which means
  5419.   only those characters that are between  A and Z, inclusive, are to be
  5420.   accepted as valid input characters.  Of course, the ASCII collating sequence
  5421.   is used.
  5422.  
  5423.   The following characters have special meanings in regular expressions:
  5424.  
  5425.    Character                      Purpose
  5426.    ---------                      -------
  5427.  
  5428.    Forward Slash (/)              Removes the special meaning of the next
  5429.                                   character in the regular expression.
  5430.  
  5431.  
  5432.    Brackets ([])                  Encloses a set of characters to be matched
  5433.                                   with the current character entered at the
  5434.                                   keyboard.  There are other special symbols
  5435.                                   that can appear in brackets:
  5436.                                   ---------------------------------------------
  5437.  
  5438.  Page 86                     The C Window Library                    Page 86
  5439.  
  5440.                                   Carat (^)    This symbol states that the
  5441.                                                character entered at the keyboard
  5442.                                                must not match any character in
  5443.                                                the brackets.  The carat must be
  5444.                                                the first character after the
  5445.                                                left bracket ([), otherwise the
  5446.                                                carat is taken literally as just
  5447.                                                another character.
  5448.  
  5449.                                   Dash  (-)    Matches character entered at
  5450.                                                keyboard with characters in ASCII
  5451.                                                order between (inclusive) the
  5452.                                                characters on either side of the
  5453.                                                dash.
  5454.  
  5455.                                   Dot   (.)    Matches any displayable ASCII
  5456.                                                character.
  5457.  
  5458.   There are two categories of regular expressions; namely simple and complex.
  5459.   Simple regular expressions only specify a single character to be entered from
  5460.   the keyboard, while complex regular expressions specify that more than a
  5461.   single character must be entered from the keyboard.
  5462.  
  5463.   Here are examples of simple regular expressions:
  5464.  
  5465.  
  5466.  
  5467.        Simple
  5468.   Regular Expression              What will be accepted
  5469.   ------------------              ---------------------
  5470.  
  5471.        [0-9]                      Accept any single digit character.
  5472.  
  5473.        [3-7]                      Accept single digit character between '3' and
  5474.                                   '7' inclusive.
  5475.  
  5476.        [A-Z]                      Accept a letter between 'A' and 'Z' inclusive.
  5477.  
  5478.        [A-Za-z]                   Accept a letter between 'A' and 'Z' or a
  5479.                                   letter between 'a' and 'z'.
  5480.  
  5481.  
  5482.        [ABCD]                     Accept either 'A', 'B', 'C', or 'D'.
  5483.  
  5484.        [A-Za-z0-9]                Accept anything between 'A' and 'Z', or
  5485.                                   'a' and 'z', or '0' and '9'
  5486.  
  5487.        [0-9ABCD]                  Accept '0' thru '9', 'A', 'B', 'C', or 'D'.
  5488.  
  5489.        [^A]                       Accept any character except 'A'.
  5490.  
  5491.        [^A-Z]                     Accept any character except the characters
  5492.                                   between 'A' and 'Z' (inclusive).
  5493.  
  5494.  Page 87                     The C Window Library                    Page 87
  5495.  
  5496.        [A-/[]                     Accept any character between 'A' and '[',
  5497.                                   inclusive.  Please note the use of the forward
  5498.                                   slash to denote that the left bracket has no
  5499.                                   special meaning.
  5500.  
  5501.        [A Z]                      Accept 'A', the space character, or 'Z'.
  5502.  
  5503.        [A/-Z]                     Accept 'A', the minus (-), or 'Z'.
  5504.  
  5505.        [/-///]]                   Accept the minus (-), the forward slash (/),
  5506.                                   or the right bracket (]).
  5507.  
  5508.        [!-&]                      Accept the ASCII characters between '!' and
  5509.                                   '&', inclusive.
  5510.  
  5511.        A                          Accept the letter 'A'.  Note that this is
  5512.                                   equivalent to [A].
  5513.  
  5514.        [9]                        Accept the digit '9'.
  5515.  
  5516.        .                          Accept any character.
  5517.  
  5518.        []                         Accept no key and call user defined function
  5519.                                   (explained later in the UNDEFINED KEYSTROKE
  5520.                                   PROCESSING section).
  5521.  
  5522.   Remember, all of the above expressions process only one character entered at
  5523.   the keyboard, even though some of the expressions can accept a variety of
  5524.   characters.
  5525.  
  5526.   As you can see there are many possibilities you can make up.  However the
  5527.   above forms of a regular expressions only work for one character entered at
  5528.   the keyboard.  What if you want to enter a persons name, address, social
  5529.   security number etc.?  You can concatenate (glue together) the regular
  5530.   expressions above to form a chain of regular expressions.  This resulting
  5531.   chain is called a complex regular expression.  Here are a few examples of
  5532.   complex regular expressions:
  5533.  
  5534.   Regular Expression              What will be accepted
  5535.   ------------------              ---------------------
  5536.      [A-Z][0-9]                   The first character entered must be between
  5537.                                   'A' and 'Z'.  The second character entered
  5538.                                   must be between '0' and '9'.
  5539.  
  5540.      [A-Z][^A-Z][0-9]             Enter three characters.  The first must be
  5541.                                   between 'A' and 'Z'.  The second can be any
  5542.                                   character except anything between 'A' and 'Z',
  5543.                                   and the third character must be between '0'
  5544.                                   and '9'.
  5545.  
  5546.   [1-9][0-9][0-9][0-9][0-9]       Enter five characters.  The first must
  5547.                                   be between '1' and '9'.  The other four
  5548.                                   characters must be between '0' and '9'.
  5549.  
  5550.  Page 88                     The C Window Library                    Page 88
  5551.  
  5552.   [A-Z][][0-9]                    The first character must be between 'A' and
  5553.                                   'Z', the second input position calls a user
  5554.                                   defined function (explained in UNDEFINED
  5555.                                   KEYSTROKE PROCESSING), and the third
  5556.                                   character must be between '0' and '9'.
  5557.  
  5558.   As you can see again, the strings can get pretty long if you wanted to setup a
  5559.   thirty character input specification, for instance, a persons name.  To save
  5560.   time typing, you can use a multiplying factor in the regular expression.  A
  5561.   multiplying factor is a number that is placed before a simple regular
  5562.   expression to denote that the simple regular expression is repeated.
  5563.  
  5564.   Here are a few examples:
  5565.  
  5566.   Regular Expression              What will be accepted
  5567.   ------------------              ---------------------
  5568.  
  5569.     25[A-Z]                       Enter twenty-five characters.  All the
  5570.                                   characters must be between 'A' and 'Z'.
  5571.  
  5572.     10[0-9]                       Enter ten characters.  All must be between
  5573.                                   '0' and '9'.
  5574.  
  5575.     5[A-C] 3[1-3]                 Enter nine characters. The first five must be
  5576.                                   between 'A' and 'C' the sixth must be the
  5577.                                   space character, and the last three must be
  5578.                                   between '1' and '3'.  Please note the space
  5579.                                   embedded in the string just before the
  5580.                                   multiplying factor 3.
  5581.  
  5582.     [1-9]2X/[5[^A-Z]/1            Enter nine characters.  The first must be
  5583.                                   between '1' and '9'.  The second and third
  5584.                                   must be 'X'. The fourth is the left bracket
  5585.                                   ([).  The next five characters entered can be
  5586.                                   any character except anything between 'A' and
  5587.                                   'Z', and the last character to accept is a
  5588.                                   '1'.  Please note the use of the forward slash
  5589.                                   just before the second left bracket and just
  5590.                                   before the last character ('1').  The
  5591.                                   forward slash before the '1' makes sure the
  5592.                                   '1' is not to be confused with a multiplying
  5593.                                   factor of 1.
  5594.  
  5595.     [A-Z]/..                      Enter three characters.  The first must be
  5596.                                   between 'A' and 'Z'.  The second is the '.',
  5597.                                   and the third is any character.
  5598.  
  5599.     10[A-Z]3[]                    Enter thirteen characters.  The first ten
  5600.                                   must be between 'A' and 'Z', and the last
  5601.                                   three input positions will call a user
  5602.                                   defined undefined key function (explained
  5603.                                   later in the UNDEFINED KEYSTROKE PROCESSING
  5604.                                   section).
  5605.  
  5606.  Page 89                     The C Window Library                    Page 89
  5607.  
  5608.   The only  limitation to what you can do with regular expressions is that you
  5609.   cannot nest regular expressions.  For example:
  5610.  
  5611.                  [A-[A-Z]]     or     20[20[a-z]]
  5612.  
  5613.   It is ok to say [9-0] instead of [0-9].  They are both equivalent and both
  5614.   accepted by The C Window Library, so there is no need to know your ASCII
  5615.   table by heart, although it is advantageous to learn it if you want to create
  5616.   sophisticated regular expression strings.  You can even use the IBM extended
  5617.   character set (ASCII values above 127) in the regular expression string.
  5618.  
  5619.  
  5620.   Editing Input
  5621.   -------------
  5622.  
  5623.   The C library function gets(x), gets a string from the keyboard and points
  5624.   the character pointer x to the string.  This function has limited editing
  5625.   capabilities.  The only keys recognized are the backspace, which serves as a
  5626.   destructive backspace (erases character immediately to the left) and the
  5627.   enter key when the user has typed in the desired string.  With The C Window
  5628.   Library, you have much more editing capabilities.
  5629.  
  5630.  
  5631.   The editing functions have the following default key values:
  5632.  
  5633.                                                                Mapped
  5634.        Function                               Key             Position
  5635.        --------                               ---              ------
  5636.      Move cursor left                    Left Arrow              0
  5637.      Move cursor right                   Right Arrow             1
  5638.      Delete character at cursor          Del (on keypad)         2
  5639.      Toggle Insert/Overwrite mode        Insert (on keypad)      3
  5640.      Erase Input and go to first column  ^E                      4
  5641.      Destructive backspace               Backspace               5
  5642.      Accept Input and return             Enter                   6
  5643.      Accept default and return           Escape                  7
  5644.      Go to first column                  Home                    8
  5645.      Move cursor to last char. entered   End                     9
  5646.  
  5647.   Here is a list of what the key functions perform:
  5648.  
  5649.  
  5650.   Move cursor left - Moves the cursor left one character.  If the beginning of
  5651.                      the input field is encountered the cursor is not moved.
  5652.  
  5653.   Move cursor right - Moves the cursor right one character.  If the end of the
  5654.                       input field is encountered, the cursor is not moved.
  5655.  
  5656.   Delete character at cursor - Deletes the character at the position of the
  5657.                                cursor.  If in insert mode, any input to the
  5658.                                right of the cursor is moved one character to
  5659.                                the left.  If in overwrite mode, no characters
  5660.                                are moved.
  5661.  
  5662.  Page 90                     The C Window Library                    Page 90
  5663.  
  5664.   Toggle Insert/Overwrite Mode - toggles the input between insert and overwrite
  5665.                                  mode.  If in insert mode, the default cursor
  5666.                                  is an underline cursor.  If in overwrite mode,
  5667.                                  the default cursor is a full block.
  5668.  
  5669.   Erase Input - Deletes all characters inputted and moves the cursor to the
  5670.                 first input position.
  5671.  
  5672.   Destructive Backspace - deletes the character immediately to the left of the
  5673.                           cursor and moves the cursor to the left one
  5674.                           character. If insert mode is on, the characters from
  5675.                           the current cursor position to the end of the input
  5676.                           field are also moved.
  5677.  
  5678.   Accept string - Accepts the string that is inputted and returns the string.
  5679.  
  5680.   Accept default and return - Returns the default string given to the input
  5681.                               routine.
  5682.  
  5683.   Go to first column - Moves cursor to the first input position.
  5684.  
  5685.   Go to last character - Moves cursor to the last character in the current input
  5686.   string.
  5687.  
  5688.   The keys used to perform these functions can be changed.  The mapped position
  5689.   is the offset in a table of key functions.  By changing the value there, you
  5690.   can change the key used to perform these functions.  If you do want to change
  5691.   these keys, I recommend using the key definitions found in the keycodes.h
  5692.   file.  For example, if you wanted Control-B to be the destructive backspace
  5693.   you would do as follows:
  5694.  
  5695.         window_edit_key[5] = CTRLB;
  5696.  
  5697.   The table of key functions is stored in the array window_edit_key.  The CTRLB
  5698.   stands for Control-B and its definition is found in the keycodes.h file.  To
  5699.   totally undefine a key definition, assign a 0 to the desired array position
  5700.   in window_edit_key.  For example:
  5701.  
  5702.         window_edit_key[2] = 0;
  5703.  
  5704.    undefines the delete character at cursor definition.
  5705.  
  5706.   When changing keys, make sure that the definitions all have unique key
  5707.   combinations.  If you desire more keystrokes for a particular key function,
  5708.   see Undefined Keystroke Processing below.
  5709.  
  5710.  
  5711.   Last Key Value
  5712.   --------------
  5713.  
  5714.   On exit of any of the input functions, the global integer last_key_hit
  5715.   contains the ascii code (scan code) of the key that was used to exit the
  5716.   input function.
  5717.  
  5718.  Page 91                     The C Window Library                    Page 91
  5719.  
  5720.   Default Cursor Types and Editing Mode
  5721.   -------------------------------------
  5722.  
  5723.   By default, The C Window Library starts editing input in overstrike mode.
  5724.   This means that characters are overwritten when the cursor is placed on a
  5725.   character.  The opposite of overstrike mode is insert mode, which pushes the
  5726.   characters to the right of the cursor over by one input position when a
  5727.   character is entered.  Also, the default cursor type for overstrike mode is a
  5728.   block cursor, and the default cursor for insert mode is a thin cursor.  You
  5729.   can change the startup mode, as well as the cursor types.
  5730.  
  5731.   The global variables default_cursor_type and default_cursor_mode store the
  5732.   values of the cursor shapes and the startup mode.
  5733.  
  5734.   The default_cursor_type is an array of two integers.  The OVERSTRIKEMODE
  5735.   constant is the position in the default_cursor_type array of where the
  5736.   overstrike shape of the cursor is stored.  The INSERTMODE constant is
  5737.   the position in default_cursor_type of where the insert shape of the
  5738.   cursor is stored.  Here is an example of how you would change the
  5739.   cursor types.
  5740.  
  5741.   #include "window.h"
  5742.  
  5743.   main()
  5744.   {
  5745.     WindowInitializeSystem();
  5746.     /*...*/                  /* Some code */
  5747.  
  5748.     default_cursor_type[OVERSTRIKEMODE] = CREATE_CURSOR_SHAPE(6,7);
  5749.     default_cursor_type[INSERTMODE] = THIN;
  5750.   }
  5751.  
  5752.   The CREATE_CURSOR_SHAPE() macro creates a cursor shape by using the first
  5753.   argument as the starting scan line of the cursor, and the second argument as
  5754.   the ending scan line.  Refer to VIDEO MACROS section for more information on
  5755.   CREATE_CURSOR_SHAPE().  The THIN constant is a predefined constant that
  5756.   stands for a thin cursor.  The other predefined constants for cursor shapes
  5757.   are BLOCK and INVISIBLE.
  5758.  
  5759.   To change the startup mode when an input function is called, you must change
  5760.   the default_cursor_mode global variable.  Here is how you would change the
  5761.   default mode:
  5762.  
  5763.   #include "window.h"
  5764.  
  5765.   main()
  5766.   {
  5767.     WindowInitializeSystem();
  5768.     /*...*/                  /* Some code */
  5769.     default_cursor_mode = OVERSTRIKEMODE;
  5770.   }
  5771.  
  5772.   Use the constants OVERSTRIKEMODE and INSERTMODE for the desired mode.
  5773.  
  5774.  Page 92                     The C Window Library                    Page 92
  5775.  
  5776.   Editing using a character mask
  5777.   ------------------------------
  5778.  
  5779.   The C Window Library also provides input functions that use character masks.
  5780.   For example to enter a date, you might want the user to enter a date in
  5781.   MM-DD-YY format.  Instead of the user having to enter the hyphens, it would be
  5782.   advantageous if the input field already had hyphens, and the cursor will
  5783.   advance or back up to the next input position, jumping over any hyphens
  5784.   encountered.  You can accomplish this by using a character mask.
  5785.  
  5786.   The mask is a character string which is made up of displayable characters, and
  5787.   a special character used to denote an input position.  For example, a date
  5788.   mask would look like this:
  5789.  
  5790.                                __-__-__
  5791.  
  5792.   The hyphens are displayed in the window, but the underscores are not
  5793.   displayed.  The underscores are used as a place holder, i.e. a place where
  5794.   input is expected.  By default, the input position character is an underscore,
  5795.   but you can change this.  Another example would be a social security mask:
  5796.  
  5797.                             ___-__-____
  5798.  
  5799.    a telephone mask:
  5800.                            (___) ___-____ ext: ____
  5801.  
  5802.    another date mask:
  5803.                            __/__/__
  5804.  
  5805.  
  5806.   If a character is deleted or inserted, the input manager is smart enough to
  5807.   move characters so that they do not clobber the characters that are not part
  5808.   of the input field.
  5809.  
  5810.  
  5811.  
  5812.   Editing Functions
  5813.   -----------------
  5814.  
  5815.   The following are functions that can be used to edit input with The C Window
  5816.   Library.
  5817.  
  5818.  
  5819.  
  5820.   WindowGetString()
  5821.   -----------------
  5822.  
  5823.   The WindowGetString() function gets a string from a window starting at a
  5824.   certain row and column of the window.  Here is the prototype:
  5825.  
  5826.     int WindowGetString(WPOINTER w, int row, int col, char *buffer,
  5827.                         int fillchar, int minchars, int maxwidth, int options,
  5828.                         int startpos, char *regexp)
  5829.  
  5830.  Page 93                     The C Window Library                    Page 93
  5831.  
  5832.   The first argument is the window pointer.  The second and third arguments are
  5833.   the row and column of where the input begins.  The fourth argument is a
  5834.   pointer to a character buffer where the input characters will be stored.
  5835.   Whatever null terminated string is stored in the character buffer prior to
  5836.   calling WindowGetString() will be used as a default string.   For example:
  5837.  
  5838.       strcpy(str,"ABC");
  5839.       WindowGetString(w,2,1,str,' ',3,3,0,"3[A-Z]");
  5840.  
  5841.   The default value of "ABC" will be displayed in the window when
  5842.   WindowGetString() is called.  Therefore, make sure that your string buffer
  5843.   has a 0 in the 0th position if you want to make sure your input is empty when
  5844.   WindowGetString() is called.  When inputting information, hitting the Escape
  5845.   key (or whatever the current key definition is for window_edit_key[7]) will
  5846.   abort input and will return the original default string.
  5847.  
  5848.   The fifth argument is the fill character.  This character is used to fill any
  5849.   unfilled input positions on the window.  Instead of having spaces for unfilled
  5850.   positions, you can have any character.  Try ASCII 177 or the underline
  5851.   character.  You may like the effect.
  5852.  
  5853.   The sixth argument is the minimum number of characters to accept.  If the
  5854.   number of characters entered is less than minchars, the input manager will
  5855.   not accept the input.  However, you can change this by allowing the input
  5856.   manager to call a user defined routine when it detects that the minimum
  5857.   number of characters was not satisfied.  More information on this later in
  5858.   this section.
  5859.  
  5860.   The seventh argument is the maximum width of the displayable input field.
  5861.   This argument allows for scrollable input fields.  If the maximum width of
  5862.   the displayable field is less than the total number of characters in the
  5863.   input field, the field will scroll right and left depending on the input
  5864.   position.  If the input cursor exceeds the right edge of the displayable
  5865.   field, the input is scrolled right until the next input position is visible.
  5866.   If the cursor is moved beyond the left edge of the displayable field, the
  5867.   input is scrolled left until the previous input position comes into view.
  5868.   Scrolling input fields allow for large input fields in small windows.
  5869.  
  5870.   The eighth argument is an integer representing the various options available
  5871.   for the input field.  The various options available will be discussed later
  5872.   on.
  5873.  
  5874.   The ninth argument is the starting position in the input string of where the
  5875.   cursor will be placed.  Position numbers start from 1 to the maximum number
  5876.   of input positions.  For most applications, the starting position is usually
  5877.   1.  If the starting position is not within bounds of the input string, the
  5878.   starting position is assumed to be 1.
  5879.  
  5880.   The last argument is the regular expression to use for the input.  Make
  5881.   sure that the input buffer you provide is large enough to hold the maximum
  5882.   number of characters plus one more character for the terminating null
  5883.   character.
  5884.  
  5885.  
  5886.  Page 94                     The C Window Library                    Page 94
  5887.  
  5888.   More Examples:
  5889.  
  5890.              WindowGetString(w,2,1,str,' ',1,1,NO_OPTIONS,1,"[YyNn]");
  5891.  
  5892.   This will accept one character but only if the character is 'Y','y','N', or
  5893.   'n'.  Another example is this:
  5894.  
  5895.  
  5896.              WindowGetString(w,2,1,str,' ',5,5,NO_OPTIONS,1,"5[0-9]");
  5897.  
  5898.   This will allow the user to enter five digit characters.
  5899.  
  5900.  
  5901.   To accept all characters, use this:
  5902.              WindowGetString(w,2,1,str,' ',3,3,NO_OPTIONS,1,".");
  5903.  
  5904.  
  5905.   Example Program:
  5906.  
  5907.  
  5908.   #include "window.h"
  5909.   #include <string.h>
  5910.   #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  5911.  
  5912.   WPOINTER w;
  5913.   char buffer[80];
  5914.   main()
  5915.   {
  5916.     int i,row,col;
  5917.     buffer[0] = 0;   /* Make sure first character is null */
  5918.     WindowInitializeSystem();
  5919.     WindowSaveInitial(0);
  5920.     w = WindowInitialize(BORDER,1,1,40,10,NORM,NORM,SINGLEBOX);
  5921.     WindowOpen(w);
  5922.     WindowDisplay(w,1,NOEFFECT);
  5923.     buffer[0] = 0;   /* Make sure first character is NULL */
  5924.     WindowWriteString(w,"Enter Your first name :",1,1);
  5925.     WindowGetString(w,2,1,buffer,' ',0,40,NO_OPTIONS,1,"40.");
  5926.     WindowWriteString(w,"You entered the following:",3,1);
  5927.     WindowWriteString(w,buffer,4,1);
  5928.     GET_KEY();
  5929.     WindowWriteString(w,"Now Enter your last name:",6,1);
  5930.  
  5931.     /* Note that the last string is now used as a default */
  5932.     WindowGetString(w,7,1,buffer,' ',0,40,NO_OPTIONS,1,"40.");
  5933.     WindowWriteString(w,"You entered the following:",8,1);
  5934.     WindowWriteString(w,buffer,9,1);
  5935.   }
  5936.  
  5937.  
  5938.  
  5939.  
  5940.  
  5941.  
  5942.  Page 95                     The C Window Library                    Page 95
  5943.  
  5944.  
  5945.   If there are no errors, WindowGetString() returns NO_ERROR.
  5946.   If there are errors, WindowGetString() returns the following:
  5947.  
  5948.   BAD_WINDOW if the window does not exist.
  5949.  
  5950.   WINDOW_NOT_OPEN if the window is not open for writing (use WindowOpen())
  5951.  
  5952.   NO_HEAP_MEM if there is not enough memory to allocate for internal buffers.
  5953.  
  5954.   NO_INPUT_CHARS if the regular expression indicates no characters to accept.
  5955.  
  5956.  
  5957.   WindowGetStringAttr()
  5958.   ---------------------
  5959.  
  5960.   The WindowGetStringAttr() function is the same as the WindowGetString()
  5961.   function described above except that a video attribute is used for the input
  5962.   entered.  Here is the prototype:
  5963.  
  5964.     int WindowGetStringAttr(WPOINTER w, int row, int col, char *buffer,
  5965.                             int fillchar, int minchars, int maxwidth,
  5966.                             int options, int startpos, int attr, char *regexp)
  5967.  
  5968.   Note that attr is the tenth argument.  This is the video attribute to use when
  5969.   receiving input.
  5970.  
  5971.  
  5972.   Example Program:
  5973.  
  5974.   #include "window.h"
  5975.   #define NORM    CREATE_VIDEO_ATTRIBUTE(black,white)
  5976.   #define REVERSE CREATE_VIDEO_ATTRIBUTE(white,black)
  5977.  
  5978.   WPOINTER w;
  5979.   char buffer[80];
  5980.   main()
  5981.   {
  5982.     int i,row,col;
  5983.     buffer[0] = 0;   /* Make sure first character is NULL */
  5984.     WindowInitializeSystem();
  5985.     WindowSaveInitial(0);
  5986.     w = WindowInitialize(BORDER,1,1,40,10,NORM,NORM,SINGLEBOX);
  5987.     WindowOpen(w);
  5988.     WindowDisplay(w,1,NOEFFECT);
  5989.     buffer[0] = 0;   /* Make sure first character is null */
  5990.     WindowWriteString(w,"Enter Your first name :",1,1);
  5991.     WindowGetStringAttr(w,2,1,buffer,' ',0,40,NO_OPTIONS,1,REVERSE,"40.");
  5992.     WindowWriteString(w,"You entered the following:",3,1);
  5993.     WindowWriteString(w,buffer,4,1);
  5994.     GET_KEY();
  5995.     WindowWriteString(w,"Now Enter your last name:",6,1);
  5996.  
  5997.  
  5998.  Page 96                     The C Window Library                    Page 96
  5999.  
  6000.     /* Note that the last string is now used as a default */
  6001.     WindowGetStringAttr(w,7,1,buffer,' ',0,40,NO_OPTIONS,1,REVERSE,"40.");
  6002.     WindowWriteString(w,"You entered the following:",8,1);
  6003.     WindowWriteString(w,buffer,9,1);
  6004.   }
  6005.  
  6006.   The return values for WindowGetStringAttr() are the same as
  6007.   WindowGetString().
  6008.  
  6009.  
  6010.  
  6011.  
  6012.   WindowGetMaskString()
  6013.   ---------------------
  6014.  
  6015.   The WindowGetMaskString() function is the same as the WindowGetString()
  6016.   except that a character mask is used when editing the input.  Here is the
  6017.   prototype:
  6018.  
  6019.     int WindowGetMaskString(WPOINTER w, int row, int col, char *buffer,
  6020.                             char *mask, int fillchar, int minchars,
  6021.                             int maxwidth, int options, int startpos,
  6022.                             char *regexp)
  6023.  
  6024.   The mask argument is an extra argument.  This is the character mask to use
  6025.   when editing the input.  The string returned in the buffer does not contain
  6026.   any characters that are used for the mask.  For instance, if the mask is
  6027.   "__/__/__", and the string entered is "121589", WindowGetMaskString() will
  6028.   place "121589" into the buffer.  If you want to create a string with the
  6029.   components separated according to a mask pattern, use the
  6030.   TranslateStringToMaskString() function described later in the manual.
  6031.  
  6032.   Example:
  6033.  
  6034.   #include "window.h"
  6035.   #include <string.h>
  6036.   #define NORM    CREATE_VIDEO_ATTRIBUTE(black,white)
  6037.   #define TELMASK "(___)___-____ ext:____"
  6038.   #define SSMASK  "___-__-____"
  6039.  
  6040.   WPOINTER w;
  6041.   char buffer[80];
  6042.   main()
  6043.   {
  6044.     int i,row,col;
  6045.     buffer[0] = 0;   /* Make sure first character is null */
  6046.     WindowInitializeSystem();
  6047.     WindowSaveInitial(0);
  6048.     w = WindowInitialize(BORDER,1,1,40,10,NORM,NORM,SINGLEBOX);
  6049.     WindowOpen(w);
  6050.     WindowDisplay(w,1,NOEFFECT);
  6051.     buffer[0] = 0;   /* Make sure first character is null */
  6052.     WindowWriteString(w,"Enter Your Telephone No.",1,1);
  6053.  
  6054.  Page 97                     The C Window Library                    Page 97
  6055.  
  6056.     WindowGetMaskString(w,2,1,buffer,TELMASK,' ',0,40,NO_OPTIONS,1,"40.");
  6057.     WindowWriteString(w,"You entered the following phone no:",3,1);
  6058.     WindowWriteString(w,buffer,4,1);
  6059.     GET_KEY();
  6060.     memset(buffer,0,sizeof(buffer));
  6061.     WindowWriteString(w,"Now Enter your Soc. Sec. Number:",6,1);
  6062.     WindowGetMaskString(w,7,1,buffer,SSMASK,' ',0,40,NO_OPTIONS,1,"40.");
  6063.     WindowWriteString(w,"You entered the following:",8,1);
  6064.     WindowWriteString(w,buffer,9,1);
  6065.   }
  6066.  
  6067.   If there are no errors, WindowGetMaskString() returns NO_ERROR.
  6068.   If there are errors, WindowGetMaskString() returns the following:
  6069.  
  6070.  
  6071.   BAD_WINDOW if the window does not exist.
  6072.  
  6073.   WINDOW_NOT_OPEN if the window is not open for writing (use WindowOpen())
  6074.  
  6075.   NO_HEAP_MEM if there is not enough memory to allocate for internal buffers.
  6076.  
  6077.  
  6078.  
  6079.  
  6080.   WindowGetMaskStringAttr()
  6081.   -------------------------
  6082.  
  6083.   The WindowGetMaskStringAttr() functions works the same way as
  6084.   WindowGetMaskString() except that WindowGetMaskStringAttr() allows you to
  6085.   specify a video attribute to use for the characters that are entered.  Here
  6086.   is the prototype:
  6087.  
  6088.   int WindowGetMaskStringAttr(WPOINTER w, int row, int col, char *buffer,
  6089.                               char *mask, int fillchar, int minchars,
  6090.                               int maxwidth, int options, int startpos,
  6091.                               int attr, char *regexp)
  6092.  
  6093.   Example:
  6094.  
  6095.   #include "window.h"
  6096.   #include <string.h>
  6097.   #define NORM    CREATE_VIDEO_ATTRIBUTE(black,white)
  6098.   #define REVERSE CREATE_VIDEO_ATTRIBUTE(white,black)
  6099.   #define TELMASK "(___)___-____ ext:____"
  6100.   #define SSMASK  "___-__-____"
  6101.   WPOINTER w;
  6102.   char buffer[80];
  6103.   main()
  6104.   {
  6105.     int i,row,col;
  6106.     buffer[0] = 0;   /* Make sure first character is null */
  6107.     WindowInitializeSystem();
  6108.     WindowSaveInitial(0);
  6109.  
  6110.  
  6111.  Page 98                     The C Window Library                    Page 98
  6112.  
  6113.     w = WindowInitialize(BORDER,1,1,40,10,NORM,NORM,SINGLEBOX);
  6114.     WindowOpen(w);
  6115.     WindowDisplay(w,1,NOEFFECT);
  6116.     buffer[0] = 0;   /* Make sure first character is null */
  6117.     WindowWriteString(w,"Enter Your Telephone No.",1,1);
  6118.     WindowGetMaskStringAttr(w,2,1,buffer,TELMASK,' ',0,40,NO_OPTIONS,1,
  6119.                             REVERSE,"40.");
  6120.     WindowWriteString(w,"You entered the following phone no:",3,1);
  6121.     WindowWriteString(w,buffer,4,1);
  6122.     GET_KEY();
  6123.     memset(buffer,0,sizeof(buffer));
  6124.     WindowWriteString(w,"Now Enter your Soc. Sec. Number:",6,1);
  6125.     WindowGetMaskStringAttr(w,7,1,buffer,SSMASK,' ',0,40,NO_OPTIONS,1,
  6126.                             REVERSE,"40.");
  6127.     WindowWriteString(w,"You entered the following:",8,1);
  6128.     WindowWriteString(w,buffer,9,1);
  6129.   }
  6130.  
  6131.   The return values for WindowGetMaskStringAttr() are the same as
  6132.   WindowGetMaskString().
  6133.  
  6134.  
  6135.   Getting Passwords
  6136.   -----------------
  6137.  
  6138.   The C Window Library also allows you to receive hidden input.  The functions
  6139.   to perform this are WindowGetPassword(), WindowGetMaskPassword(),
  6140.   WindowGetPasswordAttr() and WindowGetMaskPasswordAttr().  These functions are
  6141.   similar to the other WindowGetxx() functions. except that a character
  6142.   specified by you is displayed instead of the actual key pressed.
  6143.  
  6144.  
  6145.   WindowGetPassword()
  6146.   -------------------
  6147.  
  6148.   The WindowGetPassword() function gets hidden input from a window.  Here is
  6149.   the prototype:
  6150.  
  6151.   int WindowGetPassword(WPOINTER w, int row, int col, char *buffer,
  6152.                         int fillchar, int passchar, int minchars, int maxwidth,
  6153.                         int options, int startpos, char *regexp)
  6154.  
  6155.   The first argument is the window pointer.  The second and third arguments are
  6156.   the (row,col) to start receiving input.  The fourth argument is the buffer
  6157.   to store the inputted characters.  The fifth argument is the character to use
  6158.   to fill empty input positions on the screen.  The sixth argument is the
  6159.   character to display to the screen when a key is pressed.  The last four
  6160.   arguments are the same as the WindowGetString()'s last four arguments.
  6161.  
  6162.   For example, if the user typed "ABCDEF", and the passchar is '*', the screen
  6163.   will display "******".  Notice the asterisk is displayed instead of the
  6164.   actual characters inputted.
  6165.  
  6166.  
  6167.  Page 99                     The C Window Library                    Page 99
  6168.  
  6169.   Example Program:
  6170.  
  6171.   #include "window.h"
  6172.   #include <string.h>
  6173.   #define NORM    CREATE_VIDEO_ATTRIBUTE(black,white)
  6174.  
  6175.   WPOINTER w;
  6176.   char buffer[80];
  6177.   main()
  6178.   {
  6179.     int i,row,col;
  6180.     buffer[0] = 0;   /* Make sure first character is null */
  6181.     WindowInitializeSystem();
  6182.     WindowSaveInitial(0);
  6183.     w = WindowInitialize(BORDER,1,1,40,10,NORM,NORM,SINGLEBOX);
  6184.     WindowOpen(w);
  6185.     WindowDisplay(w,1,NOEFFECT);
  6186.     buffer[0] = 0;   /* Make sure first character is null */
  6187.     WindowWriteString(w,"Enter A Password",1,1);
  6188.     WindowGetPassword(w,2,1,buffer,' ','*',0,40,NO_OPTIONS,1,"40.");
  6189.     WindowWriteString(w,"You entered the following:",3,1);
  6190.     WindowWriteString(w,buffer,4,1);
  6191.   }
  6192.  
  6193.   The return values for WindowGetPassword() are the same as
  6194.   WindowGetMaskString().
  6195.  
  6196.  
  6197.  
  6198.   WindowGetPasswordAttr()
  6199.   -----------------------
  6200.  
  6201.   The WindowGetPasswordAttr() function is the same as WindowGetPassword() except
  6202.   that a video attribute is specified for the input characters.  Here is the
  6203.   prototype:
  6204.  
  6205.   int WindowGetPasswordAttr(WPOINTER w, int row, int col, char *buffer,
  6206.                             int fillchar, int passchar, int minchars,
  6207.                             int maxwidth, int options, int startpos,
  6208.                             int attr, char *regexp)
  6209.  
  6210.   Please note that the attribute argument is the next to last argument in the
  6211.   function.
  6212.  
  6213.   Example Program:
  6214.  
  6215.   #include "window.h"
  6216.   #include <string.h>
  6217.   #define NORM    CREATE_VIDEO_ATTRIBUTE(black,white)
  6218.   #define REVERSE CREATE_VIDEO_ATTRIBUTE(white,black)
  6219.  
  6220.   WPOINTER w;
  6221.   char buffer[80];
  6222.  
  6223.  Page 100                     The C Window Library                    Page 100
  6224.  
  6225.   main()
  6226.   {
  6227.     int i,row,col;
  6228.     buffer[0] = 0;   /* Make sure first character is null */
  6229.     WindowInitializeSystem();
  6230.     WindowSaveInitial(0);
  6231.     w = WindowInitialize(BORDER,1,1,40,10,NORM,NORM,SINGLEBOX);
  6232.     WindowOpen(w);
  6233.     WindowDisplay(w,1,NOEFFECT);
  6234.     buffer[0] = 0;   /* Make sure first character is null */
  6235.     WindowWriteString(w,"Enter A Password",1,1);
  6236.     WindowGetPasswordAttr(w,2,1,buffer,' ','*',0,40,NO_OPTIONS,1,REVERSE,
  6237.                           "40.");
  6238.     WindowWriteString(w,"You entered the following:",3,1);
  6239.     WindowWriteString(w,buffer,4,1);
  6240.   }
  6241.  
  6242.   The return values for WindowGetPasswordAttr() are the same as
  6243.   WindowGetMaskString().
  6244.  
  6245.  
  6246.  
  6247.   WindowGetMaskPassword()
  6248.   -----------------------
  6249.  
  6250.   The WindowGetMaskPassword() function works just like WindowGetPassword()
  6251.   except that a character mask is supplied.  Here is the prototype:
  6252.  
  6253.  
  6254.   int WindowGetMaskPassword(WPOINTER w, int row, int col, char *buffer,
  6255.                             char *mask, int fillchar, int passchar,
  6256.                             int minchars, int maxwidth, int options,
  6257.                             int startpos, char *regexp)
  6258.  
  6259.   Example:
  6260.  
  6261.  
  6262.   #include "window.h"
  6263.   #include <string.h>
  6264.   #define NORM    CREATE_VIDEO_ATTRIBUTE(black,white)
  6265.   #define CREDITCARDMASK "____-____-____-____"
  6266.  
  6267.   WPOINTER w;
  6268.   char buffer[80];
  6269.   main()
  6270.   {
  6271.     int i,row,col;
  6272.     buffer[0] = 0;   /* Make sure first character is null */
  6273.     WindowInitializeSystem();
  6274.     WindowSaveInitial(0);
  6275.     w = WindowInitialize(BORDER,1,1,40,10,NORM,NORM,SINGLEBOX);
  6276.     WindowOpen(w);
  6277.     WindowDisplay(w,1,NOEFFECT);
  6278.  
  6279.  Page 101                     The C Window Library                    Page 101
  6280.  
  6281.     buffer[0] = 0;   /* Make sure first character is null */
  6282.     WindowWriteString(w,"Enter A Credit Card #",1,1);
  6283.     WindowGetMaskPassword(w,2,1,buffer,CREDITCARDMASK,' ','*',0,40,NO_OPTIONS,
  6284.                           1,"40.");
  6285.     WindowWriteString(w,"You entered the following:",3,1);
  6286.     WindowWriteString(w,buffer,4,1);
  6287.   }
  6288.  
  6289.  
  6290.   The return values for WindowGetMaskPassword() are the same as
  6291.   WindowGetMaskString().
  6292.  
  6293.  
  6294.  
  6295.  
  6296.   WindowGetMaskPasswordAttr()
  6297.   ---------------------------
  6298.  
  6299.   The WindowGetMaskPasswordAttr() function works just like
  6300.   WindowGetMaskPassword() except that a video attribute is supplied. Here is
  6301.   the prototype:
  6302.  
  6303.  
  6304.   int WindowGetMaskPasswordAttr(WPOINTER w, int row, int col, char *buffer,
  6305.                                 char *mask, int fillchar, int passchar,
  6306.                                 int minchars, int maxwidth, int options,
  6307.                                 int startpos, int attr, char *regexp)
  6308.  
  6309.  
  6310.   Example:
  6311.  
  6312.  
  6313.   #include "window.h"
  6314.   #include <string.h>
  6315.   #define NORM    CREATE_VIDEO_ATTRIBUTE(black,white)
  6316.   #define REVERSE CREATE_VIDEO_ATTRIBUTE(white,black)
  6317.   #define CREDITCARDMASK "____-____-____-____"
  6318.  
  6319.   WPOINTER w;
  6320.   char buffer[80];
  6321.   main()
  6322.   {
  6323.     int i,row,col;
  6324.     buffer[0] = 0;   /* Make sure first character is null */
  6325.     WindowInitializeSystem();
  6326.     WindowSaveInitial(0);
  6327.     w = WindowInitialize(BORDER,1,1,40,10,NORM,NORM,SINGLEBOX);
  6328.     WindowOpen(w);
  6329.     WindowDisplay(w,1,NOEFFECT);
  6330.     buffer[0] = 0;   /* Make sure first character is null */
  6331.     WindowWriteString(w,"Enter A Credit Card #",1,1);
  6332.     WindowGetMaskPasswordAttr(w,2,1,buffer,CREDITCARDMASK,' ','*',0,40,
  6333.                               NO_OPTIONS,1,REVERSE, "40.");
  6334.  
  6335.  Page 102                     The C Window Library                    Page 102
  6336.  
  6337.     WindowWriteString(w,"You entered the following:",3,1);
  6338.     WindowWriteString(w,buffer,4,1);
  6339.   }
  6340.  
  6341.  
  6342.   The return values for WindowGetMaskPasswordAttr() are the same as
  6343.   WindowGetMaskString().
  6344.  
  6345.  
  6346.  
  6347.  
  6348.  
  6349.  
  6350.  
  6351.  
  6352.  
  6353.  
  6354.  
  6355.  
  6356.  
  6357.  
  6358.  
  6359.  
  6360.  
  6361.  
  6362.  
  6363.  
  6364.  
  6365.  
  6366.  
  6367.  
  6368.  
  6369.  
  6370.  
  6371.  
  6372.  
  6373.  
  6374.  
  6375.  
  6376.  
  6377.  
  6378.  
  6379.  
  6380.  
  6381.  
  6382.  
  6383.  
  6384.  
  6385.  
  6386.  
  6387.  
  6388.  
  6389.  
  6390.  
  6391.  Page 103                     The C Window Library                    Page 103
  6392.  
  6393.                         UNDEFINED KEYSTROKE PROCESSING
  6394.                         ------------------------------
  6395.  
  6396.   Another powerful feature of the input functions is that you can call a
  6397.   function for keys that are not in the current key definitions.  For instance,
  6398.   say you want the Enter key AND Control-R to mean accept the input.  Since
  6399.   there is only room for one definition for accept input, you can write a
  6400.   function that checks for the Control-R key, and return a number to the input
  6401.   manager as to what action to take.
  6402.  
  6403.   The undef_fkey_func and undef_akey_func function pointers
  6404.   ---------------------------------------------------------
  6405.  
  6406.   There are two global variables, undef_fkey_func and undef_akey_func.  Both of
  6407.   these function pointers are defined in the file key.h.  These two variables
  6408.   are pointers to functions that return an integer.  By setting these functions
  6409.   to point to your own functions, you can process undefined keystrokes yourself
  6410.   and return to the input manager what action to take.
  6411.  
  6412.   The undef_fkey_func is used to define keys that are not normal ASCII keys.
  6413.   For instance, Control key and Alt key combinations, the F-keys, PgDn and PgUp,
  6414.   etc.  The undef_akey_func is used to define normal ASCII keys (keys with ASCII
  6415.   values between 32 and 255, inclusive).
  6416.  
  6417.   Whenever an undefined key is encountered, the input manager will pass the
  6418.   string that has been currently entered, the current key pressed, the current
  6419.   position number of the character being processed, and a pointer to a new
  6420.   position to place the input cursor.  The prototype for this function is as
  6421.   follows:
  6422.  
  6423.             int (*undef_fkey_func)(char *str,/* string currently entered */
  6424.                                    int key,  /* key that was pressed */
  6425.                                    int pos, /* position number of current
  6426.                                                character being processed */
  6427.                                 int *newposptr) /* pointer to new position */
  6428.  
  6429.   The prototype to the undef_akey_func is similar to the one above.
  6430.  
  6431.   The str is a pointer to a null-terminated string of characters that has been
  6432.   currently entered.  For instance, if the string currently entered is
  6433.  
  6434.               ABC123
  6435.  
  6436.   str will point to "ABC123".
  6437.  
  6438.   The second argument is the last key that was pressed.  You should use the
  6439.   values defined in the header file "keycodes.h" if you want to check for
  6440.   non-ascii keys.  This will ensure that you are properly checking the
  6441.   keystroke desired.  For instance, if you want to check if the key pressed was
  6442.   the Page Up key, use the constant PGUP defined in keycodes.h.
  6443.  
  6444.  
  6445.  
  6446.  
  6447.  Page 104                     The C Window Library                    Page 104
  6448.  
  6449.   The third argument is an integer representing the position number of the
  6450.   current character that the cursor is on.  The first character is at position
  6451.   number 0, the second character in the input field is 1, etc.  If there is an
  6452.   input mask (as in WindowGetMaskString() and WindowGetMaskStringAttr()) the
  6453.   position number does not include any characters that are used to create the
  6454.   non-input positions.  For instance:
  6455.  
  6456.                       "__/__/__ "
  6457.                        01 23 45
  6458.  
  6459.   The numbers under the mask are the position numbers for each character.
  6460.  
  6461.   The fourth argument is a pointer to an integer representing a new position
  6462.   to move the cursor.  Use of this pointer will be explained later.
  6463.   for this argument will be made evident later.  The reason for the third
  6464.   argument being a pointer rather than an integer will be evident later on.
  6465.  
  6466.  
  6467.  
  6468.   Specifying when to call an undefined key function in a Regular Expression
  6469.   -------------------------------------------------------------------------
  6470.  
  6471.   An empty bracketed simple regular expression tells the input manager to call
  6472.   the undefined keystroke function.  An example of this type of regular
  6473.   expression is as follows:
  6474.  
  6475.           Regular                  Definition
  6476.         Expression                 ----------
  6477.         ----------
  6478.  
  6479.          [A-Z][]                  The first input position must be btween 'A'
  6480.                                   and 'Z', and the second position will
  6481.                                   automatically call the user defined undefined
  6482.                                   keystroke function.
  6483.  
  6484.          20[]                     All twenty input positions will call the
  6485.                                   undefined keystroke function.
  6486.  
  6487.          3[0-9]2[]2[A-Z]          The first three input positions must be
  6488.                                   between '0' and '9', the next two input
  6489.                                   positions automatically call the undefined
  6490.                                   keystroke function, and the last two
  6491.                                   positions must be between 'A' and 'Z'.
  6492.  
  6493.  
  6494.  
  6495.   If you use this form of a regular expression, you MUST have defined an
  6496.   undefined keystroke function.  If you did not define one, you will more than
  6497.   likely get into an infinite loop.  Using this form of regular expression
  6498.   combined with the return values (defined below) that can be returned to the
  6499.   input manager, you will virtually have total control of the way the input is
  6500.   handled.
  6501.  
  6502.  
  6503.  Page 105                     The C Window Library                    Page 105
  6504.  
  6505.   Return Values To The Input Manager
  6506.   ----------------------------------
  6507.  
  6508.   When writing your function you must return an integer to the input manager.
  6509.   This integer will inform the input manager as to what action to take.  Here
  6510.   are a list of the return values and what they inform the input manager:
  6511.  
  6512.  
  6513.  
  6514.     Return                         Action to
  6515.     Value                            Take
  6516.     ------                         ---------
  6517.  
  6518.     DONT_PROCESS           Do not Process keystroke and continue getting
  6519.                            input.
  6520.     MOVE_CURSOR_LEFT       Move cursor left.
  6521.     MOVE_CURSOR_RIGHT      Move cursor right.
  6522.     DELETE_AT_CURSOR       Delete character at cursor.
  6523.     TOGGLE_INSERT          Toggle Insert/Overwrite mode.
  6524.     DESTRUCT_BACKSPACE     Destructive Backspace.
  6525.     ACCEPT_INPUT           Accept Input and return string.
  6526.     ACCEPT_DEFAULT         Accept default string and return.
  6527.     ERASE_INPUT            Erase Input and go to first character in input field.
  6528.     GOTO_FIRST             Go to first input character in field.
  6529.     GOTO_LAST              Move cursor to last input character in field.
  6530.     MOVE_TO_CHARACTER      Move cursor to input position specified in the *pos
  6531.                            argument.
  6532.     INSERT_CHARACTER       Accept character as valid and insert it at the
  6533.                            current cursor position.
  6534.  
  6535.  
  6536.  
  6537.   The MOVE_TO_CHARACTER return value moves the input cursor to the position in
  6538.   the input string specified in the fourth argument of undef_akey_func or
  6539.   undef_fkey_func.  If you recall, the fourth argument was a pointer to an
  6540.   integer.
  6541.  
  6542.   The INSERT_CHARACTER return value only applies to the function pointed to by
  6543.   undef_akey_func.
  6544.  
  6545.   These user-defined functions can do anything, not just process keystrokes.
  6546.   For instance, if you want F1 to be a help key, where the help function is
  6547.   in a function called do_help() you must make sure that:
  6548.  
  6549.   a) the F1 key is undefined (not defined in the window_edit_key array)
  6550.   b) the undef_fkey_func function pointer points to your function
  6551.   c) return an integer to the input manager from your function.
  6552.  
  6553.   Here is a typical way that this would be set up:
  6554.  
  6555.  
  6556.  
  6557.  
  6558.  
  6559.  Page 106                     The C Window Library                    Page 106
  6560.  
  6561.   #include "window.h"
  6562.  
  6563.   /*  ... Other #includes and #defines */
  6564.  
  6565.   int do_help();           /* define help function */
  6566.  
  6567.   main()
  6568.   {
  6569.     WindowInitializeSystem();
  6570.  
  6571.  
  6572.     /* ...Some code */
  6573.     undef_fkey_func = do_help;       /* point function pointer to do_help */
  6574.     WindowGetString(/*  ... Parameters */);    /* call input function */
  6575.  
  6576.     /* ... Other code */
  6577.   }
  6578.  
  6579.  
  6580.  
  6581.   int do_help(char *str, int ch, int pos, int *newpos)
  6582.   {
  6583.     if (ch == F1)                     /* check for F1 */
  6584.     {
  6585.        /* help function goes here */
  6586.       return DONT_PROCESS;  /* make sure input manager does not process this
  6587.                                or any other undefined keystroke */
  6588.  
  6589.     }
  6590.     else
  6591.     {
  6592.       *newpos = 3;            /* move input cursor to the third input position */
  6593.       return MOVE_TO_CHARACTER;  /* let input manager know we want to move the
  6594.                                     input cursor */
  6595.     }
  6596.   }
  6597.  
  6598.  
  6599.   With this flexibility in the input functions, you can totally control how
  6600.   input is handled.
  6601.  
  6602.  
  6603.  
  6604.  
  6605.  
  6606.  
  6607.  
  6608.  
  6609.  
  6610.  
  6611.  
  6612.  
  6613.  
  6614.  
  6615.  Page 107                     The C Window Library                    Page 107
  6616.  
  6617.                                  INPUT OPTIONS
  6618.                                  -------------
  6619.  
  6620.   In the previous examples, the available options were discussed briefly.
  6621.   These options provide further control of the input functions.  Here is a list
  6622.   of the options that are available:
  6623.  
  6624.           Option                   Definition
  6625.           ------                   ----------
  6626.           UPPERCASE             Translates and displays lower case to upper
  6627.                                 case.
  6628.  
  6629.           LOWERCASE             Translates and displays upper case to lower
  6630.                                 case.
  6631.  
  6632.           CHECKSPACES           Spaces are counted when determining whether
  6633.                                 the minimum number of characters are entered.
  6634.  
  6635.           ENHANCEDKEY           Use the enhanced keyboard keys and
  6636.                                 distinguish between keypad keys and separate
  6637.                                 cursor pad keys.  Also detect F11 and F12 keys.
  6638.  
  6639.           CHECKREGEXP           Check to see if all characters entered agree
  6640.                                 with the regular expression provided.
  6641.  
  6642.           AUTORETURN            Automatically accept the input when a character
  6643.                                 in the last input position is entered.
  6644.  
  6645.           HOMECURSOR            Move scrolled input back to the first
  6646.                                 character in the input string when input is
  6647.                                 accepted.
  6648.  
  6649.           CLEARFIELD            Clears the input field if the first key pressed
  6650.                                 is recognized by the regular expression as a
  6651.                                 valid input key.  If a cursor movement key is
  6652.                                 pressed first, the field is not cleared if any
  6653.                                 subsequent input keys are pressed.
  6654.  
  6655.           USEMOUSE              Utilize the mouse to move the cursor in the
  6656.                                 input field.
  6657.  
  6658.           NO_OPTIONS            No options desired.
  6659.  
  6660.  
  6661.  
  6662.  
  6663.   UPPERCASE
  6664.   ---------
  6665.   The UPPERCASE option converts and displays all lower case letters to upper
  6666.   case while the user is inputting characters.
  6667.  
  6668.  
  6669.  
  6670.  
  6671.  Page 108                     The C Window Library                    Page 108
  6672.  
  6673.   LOWERCASE
  6674.   ---------
  6675.   The LOWERCASE option converts and displays all upper case letters to lower
  6676.   case while the user is inputting characters.
  6677.  
  6678.  
  6679.   CHECKSPACES
  6680.   -----------
  6681.   The CHECKSPACES option will cause the input manager to count any embedded
  6682.   spaces when determining whether the minimum number of characters are reached.
  6683.   Trailing spaces are counted only if the user explicitly put them there.
  6684.  
  6685.  
  6686.  
  6687.   ENHANCEDKEY
  6688.   -----------
  6689.   The ENHANCEDKEY option will distinguish between the cursor keys on the keypad
  6690.   from the dedicated cursor keys on the enhanced keyboards as well as the Ins,
  6691.   Home, Del, PgUp and PgDn keys.  Also the F11 and F12 keys will be detected.
  6692.  
  6693.  
  6694.  
  6695.   CHECKREGEXP and the reg_exp_error_func function pointer
  6696.   -------------------------------------------------------
  6697.  
  6698.   The CHECKREGEXP option will check to make sure that every character inputted
  6699.   is a valid character according to the regular expression.  When inserting or
  6700.   deleting characters during input, characters may be moved left or right
  6701.   depending on whether the input is in insert or overwrite mode.  When the
  6702.   characters are moved, the resulting pattern of characters may not match the
  6703.   regular expression desired.  For instance, if the regular expression is
  6704.   "3[A-Z]2[0-9]", meaning 3 characters between A and Z followed by 2 characters
  6705.   between 0 and 9, and the current input entered is as follows :
  6706.  
  6707.                  ABC34
  6708.  
  6709.   If the cursor is currently under the 'C', the delete key is pressed, and
  6710.   the input is currently in insert mode, the '34' will be moved one character to
  6711.   the left.  The resulting input would then look like this:
  6712.  
  6713.                  AB34
  6714.  
  6715.   As you can see, the input does not match the regular expression "3[A-Z]2[0-9]"
  6716.   because the '3' is in a position that should be occupied by a letter.  When
  6717.   the CHECKREGEXP option is chosen, each position is checked when the user wants
  6718.   to accept the string, not while the user is entering characters.  If the
  6719.   input is not OK, the input manager will not accept the string. You can
  6720.   override this by setting the reg_exp_error_func function pointer.
  6721.  
  6722.  
  6723.   The global function pointer reg_exp_error_func is prototyped as follows:
  6724.  
  6725.      int (*reg_exp_error_func)(char *buf, int nomatch);
  6726.  
  6727.  Page 109                     The C Window Library                    Page 109
  6728.  
  6729.   where buf is the current string entered, and nomatch is the position of the
  6730.   first non-matching character that did not match the regular expression.  The
  6731.   first character of the string is at position 0.
  6732.  
  6733.   Your function must return an integer back as to what to do.  There are two
  6734.   valid return values, namely ACCEPT_INPUT and DONT_PROCESS.  A return value of
  6735.   ACCEPT_INPUT will accept the input, even though all of the characters do not
  6736.   match the regular expression.  DONT_PROCESS tells the input manager to keep
  6737.   getting input.  Here is an example:
  6738.  
  6739.  
  6740.     int my_check_func();
  6741.     main()
  6742.     {
  6743.         ...
  6744.        reg_exp_error_func = my_check_func;
  6745.  
  6746.        WindowGetString(other parameters, CHECKREGEXP,"[A-Z][0-9]");
  6747.  
  6748.         ...
  6749.     }
  6750.  
  6751.     int my_check_func(char *buf, int mistake_pos)
  6752.     {
  6753.       /* Assume w is initialized and open for writing */
  6754.  
  6755.       WindowPrintf(w,
  6756.               "Illegal input for %s.  Illegal character at position %d",buf,
  6757.                mistake_pos);
  6758.       GET_KEY();
  6759.       WindowHide(w,NOEFFECT);
  6760.       return DONT_PROCESS;
  6761.     }
  6762.  
  6763.  
  6764.   The above example shows a function called my_check_func() which will be
  6765.   called when the input manager detects that all of the characters in the
  6766.   buffer buf do not match the regular expression.  The function displays a
  6767.   message in a window and waits for a key to be pressed.  Then the function
  6768.   returns DONT_PROCESS back to the input manager.
  6769.  
  6770.  
  6771.  
  6772.   AUTORETURN
  6773.   ----------
  6774.  
  6775.   The AUTORETURN will automatically accept the input and return to the calling
  6776.   function if the cursor is on the last input position and the user types a
  6777.   valid character.  Of course, if CHECKREGEXP is on, the input is checked for
  6778.   validity.
  6779.  
  6780.  
  6781.  
  6782.  
  6783.  Page 110                     The C Window Library                    Page 110
  6784.  
  6785.   HOMECURSOR
  6786.   ----------
  6787.  
  6788.   The HOMECURSOR options will scroll an input field back to the first position
  6789.   when the input is accepted.
  6790.  
  6791.  
  6792.   CLEARFIELD
  6793.   ----------
  6794.  
  6795.   The CLEARFIELD option will automatically clear the input field of any
  6796.   characters if the first key struck is a key recognized as a valid input key,
  6797.   and the character is displayed in the input position.  If the first key
  6798.   struck is a cursor movement key or a delete character key (destructive
  6799.   backspace or delete character), any valid input key that is subsequently
  6800.   struck does not clear the field,  but is recorded in the input field.
  6801.  
  6802.  
  6803.   USEMOUSE
  6804.   --------
  6805.  
  6806.   This option can only be used if you have access to The C Window Library
  6807.   MouseLib functions, the system has a mouse installed, and the mouse has been
  6808.   activated.  By positioning the mouse cursor to any valid input position in
  6809.   the input field and pressing the mouse button defined in the global integer
  6810.   variable field_button_press, the cursor is automatically moved to that input
  6811.   position.  If the CLEARFIELD option is used in conjunction to USEMOUSE, any
  6812.   subsequent input will not clear the field if the mouse was used to move the
  6813.   cursor.
  6814.  
  6815.  
  6816.   NO_OPTIONS
  6817.   ----------
  6818.  
  6819.   No field options desired.  In other words, all of the options defined above
  6820.   are turned off.
  6821.  
  6822.  
  6823.  
  6824.   Examples of Input Options
  6825.   -------------------------
  6826.  
  6827.   Examples:
  6828.  
  6829.     a) WindowGetString(w,1,1,str,' ',1,1,UPPERCASE,"[YyNn]");
  6830.  
  6831.     b) WindowGetString(w,1,1,str,' ',1,1,LOWERCASE,"[YyNn]");
  6832.  
  6833.     c) WindowGetStringAttr(w,2,1,str,' ',CREATE_VIDEO_ATTRIBUTE(black,white),1,
  6834.                            1,UPPERCASE | AUTORETURN,"[YyNn]");
  6835.  
  6836.  
  6837.  
  6838.  
  6839.  Page 111                     The C Window Library                    Page 111
  6840.  
  6841.     d) WindowGetString(w,1,1,str,' ',10,10,UPPERCASE | ENHANCEDKEY,"10.");
  6842.  
  6843.     e) WindowGetString(w,1,1,str,' ',20,10,CHECKREGEXP |
  6844.                                            HOMECURSOR,"10[A-Z]10[0-9]");
  6845.  
  6846.   Example a) gets one character and will automatically set this character to
  6847.              upper case.
  6848.  
  6849.           b) same as a) except character is converted to lower case.
  6850.  
  6851.           c) converts one character to uppercase and automatically accepts the
  6852.              input because the input cursor was on the last input position.
  6853.              Note the use of the bitwise OR (|) to set multiple options.
  6854.  
  6855.           d) Converts the input to uppercase and treats extra keys on an
  6856.              enhanced keyboard as different than their "normal" keys.
  6857.  
  6858.           e) On accepting of the input field, the input is checked to see if
  6859.              every position on the input field is checked to see if it matches
  6860.              the regular expression.  Once the input is accepted, the input is
  6861.              scrolled back to the first input position.
  6862.  
  6863.  
  6864.   THE num_chars_entered_func FUNCTION POINTER
  6865.   -------------------------------------------
  6866.  
  6867.   If the number of characters entered is not enough to satisfy the minimum
  6868.   number of characters allowed, by default the input manager will not return
  6869.   until the required number of characters is entered.  However, a global
  6870.   function pointer can be assigned to a user-written function that will
  6871.   be called when the input manager detects that the minimum number of
  6872.   characters was not reached.  The function pointer num_chars_entered_func is
  6873.   prototyped as follows:
  6874.  
  6875.           int (*num_chars_entered_func)(char *buf, int minchars);
  6876.  
  6877.   where buf is the current string that is entered, and minchars is the minimum
  6878.   number of characters to expect.
  6879.  
  6880.   Your function must return an integer back as to what to do.  There are two
  6881.   valid return values, namely ACCEPT_INPUT and DONT_PROCESS.  A return value of
  6882.   ACCEPT_INPUT will accept the input, even though the minimum number of
  6883.   characters was not reached.  DONT_PROCESS tells the input manager to keep
  6884.   getting input.  Here is an example:
  6885.  
  6886.  
  6887.     int my_min_func();
  6888.     main()
  6889.     {
  6890.         ...
  6891.        num_chars_entered_func = my_min_func;
  6892.         ...
  6893.     }
  6894.  
  6895.  Page 112                     The C Window Library                    Page 112
  6896.  
  6897.     int my_min_func(char *buf, int m)
  6898.     {
  6899.  
  6900.       /* Assume w is initialized and open for writing */
  6901.  
  6902.       WindowWriteString(w,"Not enough characters!",1,1);
  6903.       GET_KEY();
  6904.       WindowHide(w,NOEFFECT);
  6905.       return DONT_PROCESS;
  6906.     }
  6907.  
  6908.   The above example shows a function called my_min_func() which will be called
  6909.   when the input manager detects that the number of characters in the buffer
  6910.   buf, does not meet the minimum requirements.  The function displays a message
  6911.   in a window and waits for a key to be pressed.  Then the function returns
  6912.   DONT_PROCESS back to the input manager.
  6913.  
  6914.  
  6915.  
  6916.  
  6917.   OTHER INPUT RELATED FUNCTIONS
  6918.   -----------------------------
  6919.  
  6920.   There are other input related functions that you can use to translate strings
  6921.   into their character mask equivalents and vice-versa.
  6922.  
  6923.  
  6924.   TranslateStringToMaskString()
  6925.   -----------------------------
  6926.  
  6927.   This TranslateStringToMaskString() function takes a string and either places
  6928.   spaces, or the actual mask character between the characters in the string.  A
  6929.   pointer to the translated string is returned.  Here is the prototype:
  6930.  
  6931.  
  6932.     char *TranslateStringToMaskString(char *buffer, char *mask, char *buf2,
  6933.                                       int maskchar, int flag)
  6934.  
  6935.   The first argument is a pointer to the string to translate.  The second
  6936.   argument is the mask string to use. The third argument is a pointer to the
  6937.   buffer that will store the translated string.  The fourth argument is the
  6938.   mask character that is to be used.  This character determines where the input
  6939.   positions are.  The flag argument tells whether to include spaces between
  6940.   each component, or to use the character in the mask.
  6941.  
  6942.   You must make sure that buf2 is big enough to hold the translated string.
  6943.  
  6944.   The string length of the mask determines how far to translate the string.  If
  6945.   the mask string is shorter than the string to translate, the string is
  6946.   truncated up to the last character in the mask.  If the string to translate
  6947.   runs out of characters before the mask has been totally scanned, the extra
  6948.   characters in buf2 will either be spaces, or the characters in the mask (not
  6949.   the mask character specified in argument 4) will be copied over.
  6950.  
  6951.  Page 113                     The C Window Library                    Page 113
  6952.  
  6953.   Example:
  6954.  
  6955.       #include "window.h"
  6956.  
  6957.       #define NORM  CREATE_VIDEO_ATTRIBUTE(black,white)
  6958.       #define DATEMASK "__/__/__"
  6959.       char buf1[] = "123456";
  6960.       char buf2[9];
  6961.       WPOINTER w;
  6962.  
  6963.       main()
  6964.       {
  6965.         WindowInitializeSystem();
  6966.         WindowSaveInitial(0);
  6967.         w = WindowInitialize(BORDER,1,1,40,10,NORM,NORM,SINGLEBOX);
  6968.         WindowOpen(w);
  6969.         WindowDisplay(w,1,NOEFFECT);
  6970.         TranslateStringToMaskString(buf1,DATEMASK,buf2,'_',0);
  6971.         WindowPrintf(w,
  6972.             "The original string is %s\nThe translated string is %s\n",
  6973.              buf1,buf2);
  6974.         TranslateStringToMaskString(buf1,DATEMASK,buf2,'_',1);
  6975.         WindowPrintf(w,
  6976.             "The original string is %s\nThe translated string is %s\n",
  6977.              buf1,buf2);
  6978.       }
  6979.  
  6980.   The example above takes the string "123456" with the mask of "__/__/__".  The
  6981.   results of a translate with a flag of 0, and with a flag value of 1, is
  6982.   displayed in window w.
  6983.  
  6984.   The return value for TranslateStringToMaskString() is the pointer to the
  6985.   buffer that holds the translated string.  This string is automatically null
  6986.   terminated.
  6987.  
  6988.  
  6989.   TranslateMaskStringToString()
  6990.   -----------------------------
  6991.  
  6992.   This TranslateMaskStringToString() function does the opposite of
  6993.   TranslateStringToMaskString().  This function takes a string that has been
  6994.   translated with the TranslateStringToMaskString() or contains mask characters
  6995.   and returns the string without the extra characters.  Here is the prototype:
  6996.  
  6997.     char *TranslateMaskStringToString(char *buffer, char *mask, char *buf2,
  6998.                                       int maskchar)
  6999.  
  7000.   The first argument is a pointer to the translated string.  The second argument
  7001.   is the mask string to use. The third argument is a pointer to the buffer that
  7002.   will store the resulting string.  The fourth argument is the mask character
  7003.   that is to be used.  This character determines where the input positions are.
  7004.  
  7005.  
  7006.  
  7007.  Page 114                     The C Window Library                    Page 114
  7008.  
  7009.   You must make sure that buf2 is big enough to hold the new string.
  7010.  
  7011.   The translation stops when either the end of the buffer is reached, or the end
  7012.   of the mask string is reached.
  7013.  
  7014.  
  7015.   Example:
  7016.  
  7017.       #include "window.h"
  7018.       #include <string.h>
  7019.  
  7020.       #define NORM CREATE_VIDEO_ATTRIBUTE(black,white)
  7021.       #define DATEMASK "__/__/__"
  7022.       char buf1[] = "12/34/56";
  7023.       char buf2[9];
  7024.       WPOINTER w;
  7025.  
  7026.       main()
  7027.       {
  7028.         memset(buf2,0,sizeof(buf2));
  7029.         WindowInitializeSystem();
  7030.         WindowSaveInitial(0);
  7031.         w = WindowInitialize(BORDER,1,1,40,10,NORM,NORM,SINGLEBOX);
  7032.         WindowOpen(w);
  7033.         WindowDisplay(w,1,NOEFFECT);
  7034.         TranslateMaskStringToString(buf1,DATEMASK,buf2,'_');
  7035.         WindowPrintf(w,"The original string is %s\n"
  7036.                        "The untranslated string is %s\n", buf1,buf2);
  7037.       }
  7038.  
  7039.  
  7040.   The example above takes the string "12/34/56" with the mask of "__/__/__".
  7041.   The results of the translation is displayed in window w.
  7042.  
  7043.   The return value for TranslateMaskStringToString() is the pointer to the
  7044.   buffer that holds the translated string.  This string is automatically null
  7045.   terminated.
  7046.  
  7047.  
  7048.  
  7049.  
  7050.  
  7051.  
  7052.  
  7053.  
  7054.  
  7055.  
  7056.  
  7057.  
  7058.  
  7059.  
  7060.  
  7061.  
  7062.  
  7063.  Page 115                     The C Window Library                    Page 115
  7064.                              VIRTUAL WINDOWS
  7065.                              ---------------
  7066.  
  7067.   A virtual window can be thought of as a rectangular area filled with text.
  7068.   This rectangular region can be broken up into rows and columns, just as a
  7069.   normal window can be divided into rows and columns.  The differences between
  7070.   a virtual window and a regular window is that a virtual window's dimensions
  7071.   can be larger than the physical screen, and a virtual window is not displayed
  7072.   on the screen.  Then what good is it if you cannot display it?  You use
  7073.   regular windows to display portions of the virtual window.  If a regular
  7074.   window is used to view a virtual window, the regular window is called a
  7075.   viewport.  With this method, you can use a viewport to display a virtual
  7076.   window, and then 'pan' around, viewing different sections of the virtual
  7077.   window.  Text editors use this method to display files.  Scrolling popup
  7078.   menus also use virtual windows.
  7079.  
  7080.   With The C Window Library, you can create virtual windows of any size, up to
  7081.   available user memory.  You can have a maximum of 256 virtual windows defined
  7082.   at the same time.
  7083.  
  7084.  
  7085.  
  7086.   Using Windows as Viewports
  7087.   --------------------------
  7088.  
  7089.   If text is written to a virtual window, and there is a viewport that is
  7090.   displaying the portion of the virtual window that has changed, the viewport
  7091.   will show the change immediately.  You do not have to "repaint" or "refresh"
  7092.   the viewport to show an updated change.  That is handled internally in The C
  7093.   Window Library.  However, there is an option that will "freeze" a viewport,
  7094.   i.e. will not update automatically, if there is a change in the virtual
  7095.   window.  When the viewport is unfrozen, the changes to the virtual window are
  7096.   than displayed.
  7097.  
  7098.  
  7099.  
  7100.  
  7101.   Attributed and Non-Attributed Virtual Windows
  7102.   ---------------------------------------------
  7103.  
  7104.   There are two types of virtual windows.  You can have either a virtual window
  7105.   with its own video attributes or a virtual window which gets its video
  7106.   attributes from the viewport that is displaying the virtual window.
  7107.   Virtual windows without attributes use half as much memory as a virtual
  7108.   window with attributes, but attributed virtual window's are more flexible.
  7109.   For instance, lets say you have highlighted some text in the virtual window.
  7110.   If the virtual window is not attributed, you must write the highlight
  7111.   attribute to the viewport window using one of the window functions
  7112.   (WindowWriteStringAttr() for example), since the virtual window does not have
  7113.   the capacity to store the video attribute.  If you were to scroll the
  7114.   highlighted portion out of the viewport, you lose the highlight attribute,
  7115.   and must call the window function again to highlight the text, if the text is
  7116.   displayed again in the viewport.  With an attributed virtual window, you
  7117.  
  7118.  
  7119.  Page 116                     The C Window Library                    Page 116
  7120.  
  7121.   write the attributes to the virtual window.  Since the attributes are stored
  7122.   in the virtual window structure itself, the attributes are retained until you
  7123.   change them.
  7124.  
  7125.   From this point on, virtual windows without attributes are called NOATTRIBUTE
  7126.   virtual windows.  Virtual windows with attributes will be called ATTRIBUTE
  7127.   virtual windows.
  7128.  
  7129.  
  7130.   Virtual Window's Logical Cursor
  7131.   -------------------------------
  7132.  
  7133.   Each virtual window has its own logical cursor.  This cursor is updated
  7134.   automatically when calling VirtualPrintf(), and VirtualWriteCharacter()
  7135.   functions, or can be updated manually by calling the VirtualMoveCursor()
  7136.   function.  This cursor is independent of the screen cursor.
  7137.  
  7138.  
  7139.  
  7140.  
  7141.  
  7142.  
  7143.  
  7144.  
  7145.  
  7146.  
  7147.  
  7148.  
  7149.  
  7150.  
  7151.  
  7152.  
  7153.  
  7154.  
  7155.  
  7156.  
  7157.  
  7158.  
  7159.  
  7160.  
  7161.  
  7162.  
  7163.  
  7164.  
  7165.  
  7166.  
  7167.  
  7168.  
  7169.  
  7170.  
  7171.  
  7172.  
  7173.  
  7174.  
  7175.  Page 117                     The C Window Library                    Page 117
  7176.  
  7177.                            CREATING VIRTUAL WINDOWS
  7178.                            ------------------------
  7179.  
  7180.   The section will discuss creating virtual windows using the
  7181.   VirtualInitialize() function.
  7182.  
  7183.  
  7184.   VirtualInitialize()
  7185.   -------------------
  7186.  
  7187.   Virtual windows are created by calling the VirtualInitialize() function.
  7188.   Here is the prototype:
  7189.  
  7190.    VWPOINTER VirtualInitialize(int vwtype, unsigned nrows, unsigned ncols,
  7191.                                int attr)
  7192.  
  7193.   The VirtualInitialize() function returns a pointer to a virtual window
  7194.   structure (a VWPOINTER).  The first argument to VirtualInitialize() tells
  7195.   whether the virtual window will or will not have its own video attributes.
  7196.   If this argument is NOATTRIBUTE, the virtual window will not have attributes,
  7197.   otherwise if it is ATTRIBUTE, the virtual window will have its own
  7198.   attributes.  The second argument is the number of rows of the virtual window.
  7199.   The third argument is the number of columns.  The fourth argument is the
  7200.   attribute to use for the virtual window.  This argument is ignored if the
  7201.   virtual window is NOATTRIBUTE.
  7202.  
  7203.    Example:
  7204.  
  7205.    #include "window.h"
  7206.    #include <stdio.h>
  7207.  
  7208.    #define NORM  CREATE_VIDEO_ATTRIBUTE(black,white)
  7209.    VWPOINTER vw1,          /* virtual window pointers */
  7210.              vw2;
  7211.    main()
  7212.    {
  7213.      WindowInitializeSystem();
  7214.      /* set up a NOATTRIBUTE virtual window */
  7215.      vw1 = VirtualInitialize(NOATTRIBUTE,  /* virtual window type */
  7216.                              30,             /* Number of rows */
  7217.                              80,             /* Number of cols */
  7218.                              0);             /* Attribute      */
  7219.      /* set up an ATTRIBUTE virtual window */
  7220.      vw2 = VirtualInitialize(ATTRIBUTE,       /* virtual window type */
  7221.                              30,               /* Number of rows */
  7222.                              100,              /* Number of cols */
  7223.                              NORM);            /* Attribute      */
  7224.      if (vw1 == (VWPOINTER)0 ||
  7225.          vw2 == (VWPOINTER)0 ) /* Check if allocation worked */
  7226.        printf("Error in allocating virtual window.  The error number is %d",
  7227.                window_error_code);
  7228.    }
  7229.  
  7230.  
  7231.  Page 118                     The C Window Library                    Page 118
  7232.  
  7233.   In the above program, the VirtualInitialize() function is called.  This
  7234.   function allocates memory for the virtual window, and does other
  7235.   initializations.  Once this function is called, you can write to and read
  7236.   characters from the virtual window.
  7237.  
  7238.   Notice that the first argument to VirtualInitialize() is either the constant
  7239.   NOATTRIBUTE or ATTRIBUTE.
  7240.  
  7241.   Also note that there is a check to see whether the virtual windows could be
  7242.   allocated.   If there are no errors, VirtualInitialize() returns a valid
  7243.   VWPOINTER.  If there are errors, VirtualInitialize() returns a null VWPOINTER
  7244.   and sets the global variable window_error_code to one of the following:
  7245.  
  7246.   NO_HEAP_MEM if there is not enough memory to allocate for the virtual window.
  7247.  
  7248.   MAX_V_WINDOW if there are already 256 virtual windows defined.
  7249.  
  7250.  
  7251.  
  7252.  
  7253.  
  7254.  
  7255.  
  7256.  
  7257.  
  7258.  
  7259.  
  7260.  
  7261.  
  7262.  
  7263.  
  7264.  
  7265.  
  7266.  
  7267.  
  7268.  
  7269.  
  7270.  
  7271.  
  7272.  
  7273.  
  7274.  
  7275.  
  7276.  
  7277.  
  7278.  
  7279.  
  7280.  
  7281.  
  7282.  
  7283.  
  7284.  
  7285.  
  7286.  
  7287.  Page 119                     The C Window Library                    Page 119
  7288.  
  7289.                    ASSIGNING VIEWPORTS AND CLOSING VIEWPORTS
  7290.                    -----------------------------------------
  7291.  
  7292.   For a virtual window to have any useful purpose, it should be displayed on
  7293.   the screen.  However the virtual window may be larger than the physical
  7294.   screen.  The problem is solved by using normal windows to display parts of
  7295.   the virtual window.
  7296.  
  7297.  
  7298.  
  7299.   WindowAssignToVirtual()
  7300.   -----------------------
  7301.  
  7302.   To turn a window into a viewport onto a virtual window, you use the
  7303.   WindowAssignToVirtual() function.
  7304.  
  7305.   Here is the prototype:
  7306.  
  7307.      int WindowAssignToVirtual(WPOINTER w, VWPOINTER vw, unsigned row,
  7308.                                unsigned col)
  7309.  
  7310.   The first argument is the window that will be turned into a viewport.  The
  7311.   second argument is the virtual window that w will be assigned to.  The third
  7312.   and fourth arguments are the (row,col) of the virtual window.  This position
  7313.   is where the upper left hand corner of the viewport's text area will be
  7314.   placed.
  7315.  
  7316.   To illustrate this, here is a sample call to WindowAssignToVirtual():
  7317.  
  7318.          WindowAssignToVirtual(w,vw,5,10)
  7319.  
  7320.   The following description shows how this is to be interpreted:
  7321.  
  7322.                            VIRTUAL WINDOW
  7323.    -------------------------------------------------------------------
  7324.   |(1,1)                                                      (100,1)|
  7325.   |                                                                  |
  7326.   |         (5,10) of the virtual window is equivalent to (1,1) of   |
  7327.   |           |    the viewport.                                     |
  7328.   |           v                                                      |
  7329.   |           -----------------------                                |
  7330.   |           |(1,1) of the viewport|                                |
  7331.   |           |                     |                                |
  7332.   |           |   VIEWPORT WINDOW   |                                |
  7333.   |           |(14,1)        (14,30)|                                |
  7334.   |           -----------------------                                |
  7335.   |                                                                  |
  7336.   |(100,1)                                                 (100,100) |
  7337.   --------------------------------------------------------------------
  7338.  
  7339.  
  7340.   The viewport relative position of (1,1) is located at (5,10) of the virtual
  7341.   window.
  7342.  
  7343.  Page 120                     The C Window Library                    Page 120
  7344.  
  7345.   Example:
  7346.  
  7347.    #include "window.h"
  7348.  
  7349.    #define NORM  CREATE_VIDEO_ATTRIBUTE(black,white)
  7350.    VWPOINTER vw;          /* virtual window pointers */
  7351.    WPOINTER w;
  7352.    main()
  7353.    {
  7354.      WindowInitializeSystem();
  7355.      WindowSaveInitial(0);
  7356.      vw = VirtualInitialize(NOATTRIBUTE,30,80,0);
  7357.      w = WindowInitialize(BORDER,1, 1,20,12,NORM,NORM,SINGLEBOX);
  7358.      WindowOpen(w);
  7359.      WindowDisplay(w,1,NOEFFECT);
  7360.      VirtualWriteString(vw,"This is a string",1,1);/* Write string to virtual
  7361.                                                       window */
  7362.      WindowAssignToVirtual(w,vw,1,1);      /* Assign viewport to virtual
  7363.                                               window */
  7364.    }
  7365.  
  7366.   The above program opens a virtual window, vw, and opens a normal window, w.
  7367.   In the above example, the VirtualWriteString() function is used to write
  7368.   strings to the virtual window.  See the WRITING TEXT TO VIRTUAL WINDOWS
  7369.   section for more information on VirtualWriteString().
  7370.  
  7371.   Once a window is turned into a viewport, nothing is stopping you from using
  7372.   the other window functions.  You can still use WindowWriteString(),
  7373.   WindowMove(), WindowPrintf(), etc.  Writing text to a viewport window via the
  7374.   normal window functions does not effect the virtual window in any way.
  7375.  
  7376.   If there are no errors, WindowAssignToVirtual() returns NO_ERROR.
  7377.   If there are errors, WindowAssignToVirtual() returns the following values:
  7378.  
  7379.   BAD_WINDOW if the window does not exist.
  7380.  
  7381.   BAD_V_WINDOW if the virtual window does not exist.
  7382.  
  7383.   WINDOW_NOT_OPEN if the window is not open for writing (use WindowOpen()).
  7384.  
  7385.  
  7386.   Out of bounds Coordinates
  7387.   -------------------------
  7388.  
  7389.   The next question is "What do you do if the coordinates given in
  7390.   WindowAssignToVirtual() are out of bounds of the range of the virtual
  7391.   window?".  For instance, if the virtual window has 100 rows, but the call to
  7392.   WindowAssignToVirtual() specifies row 97, and the viewport itself has a
  7393.   height of 10 rows.  The window manager will fill the viewport with as much of
  7394.   the virtual window as possible, and will clear the contents of the viewport
  7395.   that are not inside the virtual window.
  7396.  
  7397.   Here is another view of what happens in this case:
  7398.  
  7399.  Page 121                     The C Window Library                    Page 121
  7400.  
  7401.                            VIRTUAL WINDOW
  7402.    -------------------------------------------------------------------
  7403.   |(1,1)                                                      (100,1)|
  7404.   |                                                                  |
  7405.   |           (97,10) of the virtual window is the same as (1,1) of  |
  7406.   |             |     the viewport window.                           |
  7407.   |             v                                                    |
  7408.   |             -----------------------                              |
  7409.   |             |(1,1) of the viewport|                              |
  7410.   |             |                     |                              |
  7411.   |(100,1)      |   VIEWPORT WINDOW   |                    (100,100) |
  7412.   --------------------------------------------------------------------
  7413.                 |This portion of the  |
  7414.                 |  window is cleared  |
  7415.                 -----------------------
  7416.  
  7417.   The above picture shows a viewport that is partially contained in the virtual
  7418.   window.  The contents of the window above the last row of the virtual window
  7419.   is updated, while the portion of the viewport below the line is cleared.
  7420.  
  7421.  
  7422.  
  7423.  
  7424.   WindowCloseViewport()
  7425.   ---------------------
  7426.  
  7427.   To turn a viewport back to a normal window, WindowCloseViewport() is called.
  7428.   Here is the prototype:
  7429.  
  7430.            int WindowCloseViewport(WPOINTER w, int hide, int effect)
  7431.  
  7432.   where w is the viewport to be turned back into a regular window.  When this
  7433.   function is called, the window w is cleared with its own video attribute.
  7434.   The second argument tells if the window is to be hidden. If hide is 1, the
  7435.   window is hidden.  If it is 0, the window remains on the screen.  The effect
  7436.   argument is a special effect to use when hiding the window.  A list of
  7437.   special effects are defined in the DISPLAYING WINDOWS section.  This function
  7438.   DOES NOT close the virtual window or does a WindowClose() to the viewport
  7439.   window.
  7440.  
  7441.  
  7442.   Example:
  7443.  
  7444.  
  7445.    #include "window.h"
  7446.  
  7447.    #define NORM  CREATE_VIDEO_ATTRIBUTE(black,white)
  7448.    VWPOINTER vw;          /* virtual window pointers */
  7449.    WPOINTER w;
  7450.    main()
  7451.    {
  7452.      WindowInitializeSystem();
  7453.      WindowSaveInitial(0);
  7454.  
  7455.  Page 122                     The C Window Library                    Page 122
  7456.  
  7457.      vw = VirtualInitialize(NOATTRIBUTE,30,80,0);
  7458.      w = WindowInitialize(BORDER,1, 1,20,12,NORM,NORM,SINGLEBOX);
  7459.      WindowOpen(w);
  7460.      WindowDisplay(w,1,NOEFFECT);
  7461.      VirtualWriteString(vw,"This is a string",1,1);/* Write string to virtual
  7462.                                                       window */
  7463.      WindowAssignToVirtual(w,vw,1,1);      /* Assign viewport to virtual
  7464.                                               window */
  7465.      GET_KEY();
  7466.      WindowCloseViewport(w,1,NOEFFECT);
  7467.      GETKEY();
  7468.    }
  7469.  
  7470.  
  7471.   The example above opens a virtual windows and a normal.  It then assigns the
  7472.   windows to the virtual window by calling WindowAssignToVirtual().  The
  7473.   program then unassigns the viewport by calling WindowCloseViewport().
  7474.  
  7475.   If there are no errors, WindowCloseViewport() returns NO_ERROR.
  7476.   If there are errors, WindowCloseViewport() returns the following values:
  7477.  
  7478.   BAD_WINDOW if the window does not exist.
  7479.  
  7480.   BAD_V_WINDOW if the virtual window that w is a viewport on does not exist.
  7481.  
  7482.   WINDOW_NOT_OPEN if the window is not open for writing (use WindowOpen()).
  7483.  
  7484.  
  7485.  
  7486.  
  7487.  
  7488.  
  7489.  
  7490.  
  7491.  
  7492.  
  7493.  
  7494.  
  7495.  
  7496.  
  7497.  
  7498.  
  7499.  
  7500.  
  7501.  
  7502.  
  7503.  
  7504.  
  7505.  
  7506.  
  7507.  
  7508.  
  7509.  
  7510.  
  7511.  Page 123                     The C Window Library                    Page 123
  7512.  
  7513.                         WRITING TEXT TO VIRTUAL WINDOWS
  7514.                         -------------------------------
  7515.  
  7516.   There are several functions that write strings to virtual windows.  They are
  7517.   divided into two groups: functions that take null terminated strings as
  7518.   arguments, and functions that use character buffers and a length argument.
  7519.  
  7520.   When any of the text functions are called, any viewport that is displaying
  7521.   any portion of the virtual window that has been changed will display the
  7522.   update.
  7523.  
  7524.  
  7525.   Null Terminated String Functions
  7526.   --------------------------------
  7527.  
  7528.   VirtualWriteString()
  7529.   --------------------
  7530.  
  7531.   The VirtualWriteString() function writes a null terminated to a virtual
  7532.   window at a specific row and column of the virtual window.  Here is the
  7533.   prototype:
  7534.  
  7535.         int VirtualWriteString(VWPOINTER vw, char *string, unsigned row,
  7536.                                unsigned col)
  7537.  
  7538.   The first argument is the virtual window pointer.  The second argument is the
  7539.   string to write.  The third and fourth arguments are the row and column of
  7540.   the virtual window that the string is to be written to.  If the string will
  7541.   exceed the boundaries of the virtual window, the string is truncated.
  7542.  
  7543.   Example:
  7544.  
  7545.    #include "window.h"
  7546.    #define NORM  CREATE_VIDEO_ATTRIBUTE(black,white)
  7547.    VWPOINTER vw;          /* virtual window pointers */
  7548.    WPOINTER w1, w2;
  7549.    main()
  7550.    {
  7551.      WindowInitializeSystem();
  7552.      WindowSaveInitial(0);
  7553.      vw = VirtualInitialize(NOATTRIBUTE,30,80,0);
  7554.      w1 = WindowInitialize(BORDER,1, 1,20,12,NORM,NORM,SINGLEBOX);
  7555.      w2 = WindowInitialize(BORDER,13,1,20,10,NORM,NORM,DOUBLEBOX);
  7556.      WindowOpen(w1);
  7557.      WindowOpen(w2);
  7558.      WindowDisplay(w1,1,NOEFFECT);
  7559.      WindowDisplay(w2,2,NOEFFECT);
  7560.      VirtualWriteString(vw,"This is a string",1,1);/* Write string to virtual
  7561.                                                       window */
  7562.      WindowAssignToVirtual(w1,vw,1,1); /* Assign viewport to virtual window */
  7563.      WindowAssignToVirtual(w2,vw,1,10);  /* Assign viewport to virtual
  7564.                                             window */
  7565.    }
  7566.  
  7567.  Page 124                     The C Window Library                    Page 124
  7568.  
  7569.   The example above writes the string "This is a string" to the virtual window
  7570.   at row 1, column 1.  The windows w1 and w2 are viewports on the virtual
  7571.   window vw.  The window w1 is located at (1,1) of the virtual window, while w2
  7572.   is located at (1,10) of the virtual window.  The window w1 will display "This
  7573.   is a string", but w2 will only display "string" since it is situated at
  7574.   column 10 of the virtual window.
  7575.  
  7576.  
  7577.   If there are no errors, VirtualWriteString() returns NO_ERROR.
  7578.  
  7579.   If there are errors, VirtualWriteString() returns the following values:
  7580.  
  7581.  
  7582.   BAD_V_WINDOW if the virtual window does not exist.
  7583.  
  7584.   V_WINDOW_BOUND if the either row or col is out of bounds of the virtual
  7585.   window.
  7586.  
  7587.  
  7588.  
  7589.  
  7590.   VirtualWriteStringAttr()
  7591.   ------------------------
  7592.  
  7593.   The VirtualWriteStringAttr() works the same way as the VirtualWriteString()
  7594.   except that a video attribute is used.  Here is the prototype:
  7595.  
  7596.      int VirtualWriteStringAttr(VWPOINTER vw, char *string, unsigned row,
  7597.                                 unsigned col, int attr)
  7598.  
  7599.   The last argument is the video attribute to use.  If the virtual window is
  7600.   NOATTRIBUTE, the attribute is ignored, and only the string is written.  Any
  7601.   viewports that are assigned to NOATTRIBUTE virtual windows will not reflect
  7602.   the change in the attribute.
  7603.  
  7604.   Example:
  7605.  
  7606.    #include "window.h"
  7607.    #define NORM     CREATE_VIDEO_ATTRIBUTE(black,white)
  7608.    #define REVERSE  CREATE_VIDEO_ATTRIBUTE(white,black)
  7609.    VWPOINTER vw;          /* virtual window pointers */
  7610.    WPOINTER w;
  7611.    main()
  7612.    {
  7613.      WindowInitializeSystem();
  7614.      WindowSaveInitial(0);
  7615.      vw = VirtualInitialize(ATTRIBUTE,30,80,NORM);
  7616.      w = WindowInitialize(BORDER,1, 1,20,12,NORM,NORM,SINGLEBOX);
  7617.      WindowOpen(w);
  7618.      WindowDisplay(w,1,NOEFFECT);
  7619.      VirtualWriteStringAttr(vw,"This is a string",1,1,REVERSE);
  7620.      WindowAssignToVirtual(w,vw,1,1);   /* Assign viewport to virtual window */
  7621.    }
  7622.  
  7623.  Page 125                     The C Window Library                    Page 125
  7624.  
  7625.   The example above writes the string "This is a string" in the virtual window
  7626.   with a video attribute defined by the constant REVERSE.
  7627.  
  7628.   If there are no errors, VirtualWriteStringAttr() returns NO_ERROR.
  7629.  
  7630.   If there are errors, VirtualWriteStringAttr() returns the following values:
  7631.  
  7632.   BAD_V_WINDOW if the virtual window does not exist.
  7633.  
  7634.   V_WINDOW_BOUND if the either row or col is out of bounds of the virtual
  7635.   window.
  7636.  
  7637.   NO_ATTRIB if the virtual window is NOATTRIBUTE.  If this error occurs,
  7638.   only the string is written.
  7639.  
  7640.  
  7641.  
  7642.  
  7643.   VirtualWriteCenterString()
  7644.   --------------------------
  7645.  
  7646.   The VirtualWriteCenterString() writes a centered string in a virtual window.
  7647.   Here is the prototype:
  7648.  
  7649.     int VirtualWriteCenterString(VWPOINTER vw, char *string, unsigned row)
  7650.  
  7651.   The row argument is the row to center the string on.
  7652.  
  7653.  
  7654.   Example:
  7655.  
  7656.    #include "window.h"
  7657.    #define NORM     CREATE_VIDEO_ATTRIBUTE(black,white)
  7658.    VWPOINTER vw;          /* virtual window pointers */
  7659.    WPOINTER w;
  7660.  
  7661.    main()
  7662.    {
  7663.      WindowInitializeSystem();
  7664.      WindowSaveInitial(0);
  7665.      vw = VirtualInitialize(NOATTRIBUTE,30,80,NORM);
  7666.      w = WindowInitialize(BORDER,1, 1,50,12,NORM,NORM,SINGLEBOX);
  7667.      WindowOpen(w);
  7668.      WindowDisplay(w,1,NOEFFECT);
  7669.      VirtualWriteCenterString(vw,"This is a string",1);
  7670.      WindowAssignToVirtual(w,vw,1,1);
  7671.    }
  7672.  
  7673.  
  7674.  
  7675.  
  7676.  
  7677.  
  7678.  
  7679.  Page 126                     The C Window Library                    Page 126
  7680.  
  7681.   The above example illustrates the use of VirtualWriteCenterString().  The
  7682.   viewport window w is just used as a guide to display what has happened.
  7683.  
  7684.   If there are no errors, VirtualWriteCenterString() returns NO_ERROR.
  7685.  
  7686.   If there are errors, VirtualWriteCenterString() returns the following values:
  7687.  
  7688.  
  7689.   BAD_V_WINDOW if the virtual window does not exist.
  7690.  
  7691.   V_WINDOW_BOUND if the row is out of bounds of the virtual window.
  7692.  
  7693.  
  7694.  
  7695.  
  7696.   VirtualWriteCenterStringAttr()
  7697.   ------------------------------
  7698.  
  7699.  
  7700.   The VirtualWriteCenterStringAttr() function works the same way as
  7701.   VirtualWriteCenterString() except that a video attribute is specified.  Here
  7702.   is the prototype:
  7703.  
  7704.     int VirtualWriteCenterStringAttr(VWPOINTER vw, char *string, unsigned row,
  7705.                                      int attr)
  7706.  
  7707.   The attr argument is the video attribute to use.  If the virtual window is
  7708.   NOATTRIBUTE, the attribute is ignored and only the string is written to the
  7709.   virtual window.
  7710.  
  7711.  
  7712.    #include "window.h"
  7713.  
  7714.    #define NORM     CREATE_VIDEO_ATTRIBUTE(black,white)
  7715.    #define REVERSE  CREATE_VIDEO_ATTRIBUTE(white,black)
  7716.    VWPOINTER vw;          /* virtual window pointers */
  7717.    WPOINTER w;
  7718.    main()
  7719.    {
  7720.      WindowInitializeSystem();
  7721.      WindowSaveInitial(0);
  7722.      vw = VirtualInitialize(ATTRIBUTE,30,80,NORM);
  7723.      w = WindowInitialize(BORDER,1, 1,50,12,NORM,NORM,SINGLEBOX);
  7724.      WindowOpen(w);
  7725.      WindowDisplay(w,1,NOEFFECT);
  7726.      VirtualWriteCenterStringAttr(vw,"This is a string",1,REVERSE);
  7727.      WindowAssignToVirtual(w,vw,1,1);  /* Assign viewport to virtual window */
  7728.    }
  7729.  
  7730.  
  7731.  
  7732.  
  7733.  
  7734.  
  7735.  Page 127                     The C Window Library                    Page 127
  7736.  
  7737.   If there are no errors, VirtualWriteCenterStringAttr() returns NO_ERROR.
  7738.  
  7739.   If there are errors, VirtualWriteCenterStringAttr() returns the following
  7740.   values:
  7741.  
  7742.   BAD_V_WINDOW if the virtual window does not exist.
  7743.  
  7744.   V_WINDOW_BOUND if the row is out of bounds of the virtual window.
  7745.  
  7746.   NO_ATTRIB if the virtual window is NOATTRIBUTE.  If this error occurs,
  7747.   only the string is written.
  7748.  
  7749.  
  7750.  
  7751.  
  7752.   VirtualWriteStringCC()
  7753.   ----------------------
  7754.  
  7755.   The VirtualWriteStringCC() function centers and writes a string around a
  7756.   column of the virtual window (the CC stands for Centered Column).  If the
  7757.   string is longer than the width of the virtual window, the string is placed
  7758.   on column 1 is clipped at the right edge of the virtual window.
  7759.   Here is the prototype:
  7760.  
  7761.   int VirtualWriteStringCC(VWPOINTER vw, char *string, unsigned row,
  7762.                            unsigned col)
  7763.  
  7764.   The first argument is the window.  The second argument is the string. The
  7765.   third argument is the row to write the string, and the last argument is the
  7766.   column to center the string on.
  7767.  
  7768.   Example:
  7769.  
  7770.    #include "window.h"
  7771.    #define NORM     CREATE_VIDEO_ATTRIBUTE(black,white)
  7772.    VWPOINTER vw;          /* virtual window pointers */
  7773.    WPOINTER w;
  7774.    main()
  7775.    {
  7776.      WindowInitializeSystem();
  7777.      WindowSaveInitial(0);
  7778.      vw = VirtualInitialize(NOATTRIBUTE,30,80,NORM);
  7779.      w = WindowInitialize(BORDER,1, 1,50,12,NORM,NORM,SINGLEBOX);
  7780.      WindowOpen(w);
  7781.      WindowDisplay(w,1,NOEFFECT);
  7782.      VirtualWriteStringCC(vw,"This",1,10);
  7783.      VirtualWriteStringCC(vw,"is",2,10);
  7784.      VirtualWriteStringCC(vw,"centered",3,10);
  7785.      VirtualWriteStringCC(vw,"around",4,10);
  7786.      VirtualWriteStringCC(vw,"column",5,10);
  7787.      VirtualWriteStringCC(vw,"10",6,10);
  7788.      WindowAssignToVirtual(w,vw,1,1);
  7789.    }
  7790.  
  7791.  Page 128                     The C Window Library                    Page 128
  7792.  
  7793.   The example above writes the text centered around column 10 of the virtual
  7794.   window w.
  7795.  
  7796.   The return values for VirtualWriteStringCC() are the same as
  7797.   VirtualWriteString().
  7798.  
  7799.  
  7800.  
  7801.  
  7802.  
  7803.   VirtualWriteStringCCAttr()
  7804.   --------------------------
  7805.  
  7806.   The VirtualWriteStringCCAttr() works the same way as the
  7807.   VirtualWriteStringCC() function except that a video attribute is specified.
  7808.   Here is the prototype:
  7809.  
  7810.   int VirtualWriteStringCCAttr(VWPOINTER vw, char *string, unsigned row,
  7811.                                unsigned col, int attr)
  7812.  
  7813.   The attribute to use is the last argument.  If the virtual window is
  7814.   NOATTRIBUTE, the attr argument is ignored, and only the string is written
  7815.   to the virtual window.
  7816.  
  7817.   Example:
  7818.  
  7819.    #include "window.h"
  7820.  
  7821.    #define NORM     CREATE_VIDEO_ATTRIBUTE(black,white)
  7822.    #define REVERSE  CREATE_VIDEO_ATTRIBUTE(white,black)
  7823.  
  7824.    VWPOINTER vw;          /* virtual window pointers */
  7825.    WPOINTER w;
  7826.    main()
  7827.    {
  7828.      WindowInitializeSystem();
  7829.      WindowSaveInitial(0);
  7830.      vw = VirtualInitialize(ATTRIBUTE,30,80,NORM);
  7831.      w = WindowInitialize(BORDER,1, 1,50,12,NORM,NORM,SINGLEBOX);
  7832.      WindowOpen(w);
  7833.      WindowDisplay(w,1,NOEFFECT);
  7834.      VirtualWriteStringCCAttr(vw,"This",1,10,REVERSE);
  7835.      VirtualWriteStringCCAttr(vw,"is",2,10,REVERSE);
  7836.      VirtualWriteStringCCAttr(vw,"centered",3,10,REVERSE);
  7837.      VirtualWriteStringCCAttr(vw,"around",4,10,REVERSE);
  7838.      VirtualWriteStringCCAttr(vw,"column",5,10,REVERSE);
  7839.      VirtualWriteStringCCAttr(vw,"10",6,10,REVERSE);
  7840.      WindowAssignToVirtual(w,vw,1,1);
  7841.    }
  7842.  
  7843.  
  7844.   The return values for VirtualWriteStringCCAttr() are the same as
  7845.   VirtualWriteStringAttr().
  7846.  
  7847.  Page 129                     The C Window Library                    Page 129
  7848.  
  7849.   VirtualWriteStringRJ()
  7850.   ----------------------
  7851.  
  7852.   The VirtualWriteStringRJ() function writes a right justified string in a
  7853.   virtual window.  Here is the prototype:
  7854.  
  7855.      int VirtualWriteStringRJ(WPOINTER w, char *string, unsigned row,
  7856.                               unsigned col)
  7857.  
  7858.   The first argument is the virtual window.  The second argument is the string.
  7859.   The third argument is the row to write the string, and the last argument is
  7860.   the column to place the right edge of the string.
  7861.  
  7862.  
  7863.   Example:
  7864.  
  7865.  
  7866.   #include "window.h"
  7867.   #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  7868.  
  7869.    VWPOINTER vw;          /* virtual window pointers */
  7870.    WPOINTER w;
  7871.    main()
  7872.    {
  7873.      WindowInitializeSystem();
  7874.      WindowSaveInitial(0);
  7875.      vw = VirtualInitialize(NOATTRIBUTE,30,80,NORM);
  7876.      w = WindowInitialize(BORDER,1, 1,50,12,NORM,NORM,SINGLEBOX);
  7877.      WindowOpen(w);
  7878.      WindowDisplay(w,1,NOEFFECT);
  7879.      VirtualWriteStringRJ(vw,"This",1,10);
  7880.      VirtualWriteStringRJ(vw,"is",2,10);
  7881.      VirtualWriteStringRJ(vw,"right",3,10);
  7882.      VirtualWriteStringRJ(vw,"justified",4,10);
  7883.      VirtualWriteStringRJ(vw,"on ",5,10);
  7884.      VirtualWriteStringRJ(vw,"column",6,10);
  7885.      VirtualWriteStringRJ(vw,"10",7,10);
  7886.      WindowAssignToVirtual(w,vw,1,1);
  7887.    }
  7888.  
  7889.  
  7890.   The example above writes the text right justified on column 10 of the
  7891.   virtual window.
  7892.  
  7893.   The return values for VirtualWriteStringRJ() are the same as
  7894.   VirtualWriteString().
  7895.  
  7896.  
  7897.  
  7898.  
  7899.  
  7900.  
  7901.  
  7902.  
  7903.  Page 130                     The C Window Library                    Page 130
  7904.  
  7905.   VirtualWriteStringRJAttr()
  7906.   --------------------------
  7907.  
  7908.   The VirtualWriteStringRJAttr() writes a right justified string in a virtual
  7909.   window, and allows you to specify a video attribute. Here is the prototype:
  7910.  
  7911.      int VirtualWriteStringRJAttr(WPOINTER w, char *string, unsigned row,
  7912.                                   unsigned col, int attr)
  7913.  
  7914.   The last argument is the attribute to use.
  7915.  
  7916.  
  7917.   Example:
  7918.  
  7919.  
  7920.   #include "window.h"
  7921.   #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  7922.   #define REVERSE CREATE_VIDEO_ATTRIBUTE(white,black)
  7923.  
  7924.    VWPOINTER vw;          /* virtual window pointers */
  7925.    WPOINTER w;
  7926.    main()
  7927.    {
  7928.      WindowInitializeSystem();
  7929.      WindowSaveInitial(0);
  7930.      vw = VirtualInitialize(ATTRIBUTE,30,80,NORM);
  7931.      w = WindowInitialize(BORDER,1, 1,50,12,NORM,NORM,SINGLEBOX);
  7932.      WindowOpen(w);
  7933.      WindowDisplay(w,1,NOEFFECT);
  7934.      VirtualWriteStringRJAttr(vw,"This",1,10,REVERSE);
  7935.      VirtualWriteStringRJAttr(vw,"is",2,10,REVERSE);
  7936.      VirtualWriteStringRJAttr(vw,"right",3,10,REVERSE);
  7937.      VirtualWriteStringRJAttr(vw,"justified",4,10,REVERSE);
  7938.      VirtualWriteStringRJAttr(vw,"on ",5,10,REVERSE);
  7939.      VirtualWriteStringRJAttr(vw,"column",6,10,REVERSE);
  7940.      VirtualWriteStringRJAttr(vw,"10",7,10,REVERSE);
  7941.      WindowAssignToVirtual(w,vw,1,1);
  7942.    }
  7943.  
  7944.  
  7945.   The example above writes the text right justified on column 10 of the
  7946.   virtual window.  If the virtual window is NOATTRIBUTE, only the string is
  7947.   written.
  7948.  
  7949.   The return values for VirtualWriteStringRJAttr() are the same as
  7950.   VirtualWriteStringAttr().
  7951.  
  7952.  
  7953.  
  7954.  
  7955.  
  7956.  
  7957.  
  7958.  
  7959.  Page 131                     The C Window Library                    Page 131
  7960.  
  7961.   Length Controlled Functions
  7962.   ---------------------------
  7963.  
  7964.  
  7965.  
  7966.   VirtualWriteCharacters()
  7967.   ------------------------
  7968.  
  7969.   The VirtualWriteCharacters() writes a specified number of characters from a
  7970.   buffer to the virtual window.  Here is the prototype:
  7971.  
  7972.  
  7973.     int VirtualWriteCharacters(VWPOINTER vw, char *buffer, unsigned row,
  7974.                                unsigned col, unsigned length)
  7975.  
  7976.  
  7977.   The first argument is the virtual window.  The second argument is the buffer
  7978.   where the characters are stored.  The third and fourth arguments are the
  7979.   (row,col) of where the characters will be placed in the virtual window.  The
  7980.   last argument is the number of characters from buffer that will be written.
  7981.  
  7982.  
  7983.   Example:
  7984.  
  7985.  
  7986.   #include "window.h"
  7987.   #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  7988.  
  7989.   WPOINTER w;
  7990.   VWPOINTER vw;
  7991.   char buf[] = "Hello World!!";
  7992.  
  7993.   main()
  7994.   {
  7995.     WindowInitializeSystem();
  7996.     WindowSaveInitial(0);
  7997.     w = WindowInitialize(BORDER,1,1,20,10,NORM,NORM,SINGLEBOX);
  7998.     vw = VirtualInitialize(NOATTRIBUTE,30,80,NORM);
  7999.     WindowOpen(w);
  8000.     WindowDisplay(w,1,NOEFFECT);
  8001.     VirtualWriteCharacters(vw,buf,1,1,11);  /* Writes "Hello World"   */
  8002.     VirtualWriteCharacters(vw,buf,2,1,13);  /* Writes "Hello World!!" */
  8003.     WindowAssignToVirtual(w,vw,1,1);
  8004.   }
  8005.  
  8006.  
  8007.   The return values for VirtualWriteCharacters() are the same as
  8008.   VirtualWriteString().
  8009.  
  8010.  
  8011.  
  8012.  
  8013.  
  8014.  
  8015.  Page 132                     The C Window Library                    Page 132
  8016.  
  8017.   VirtualWriteAttributes()
  8018.   ------------------------
  8019.  
  8020.   The VirtualWriteAttributes() writes a specified number of attributes from a
  8021.   buffer to the virtual window.  Here is the prototype:
  8022.  
  8023.  
  8024.     int VirtualWriteAttributes(VWPOINTER vw, char *buffer, unsigned row,
  8025.                                unsigned col, unsigned length)
  8026.  
  8027.  
  8028.   The first argument is the virtual window.  The second argument is the buffer
  8029.   where the attributes are stored.  The third and fourth arguments are the
  8030.   (row,col) of where the attributes will be placed in the virtual window.  The
  8031.   last argument is the number of attributes from buffer that will be written.
  8032.   If the window is NOATTRIBUTE, this function does nothing.
  8033.  
  8034.   Example:
  8035.  
  8036.  
  8037.   #include "window.h"
  8038.   #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  8039.   #define REVERSE CREATE_VIDEO_ATTRIBUTE(white,black)
  8040.   WPOINTER w;
  8041.   VWPOINTER vw;
  8042.   char buf[13];
  8043.  
  8044.   main()
  8045.   {
  8046.     int i;
  8047.     WindowInitializeSystem();
  8048.     WindowSaveInitial(0);
  8049.     for (i=0;i<13;i++)
  8050.       if (i % 2)
  8051.         buf[i] = NORM;
  8052.       else
  8053.         buf[i] = REVERSE;
  8054.     w = WindowInitialize(BORDER,1,1,20,10,NORM,NORM,SINGLEBOX);
  8055.     vw = VirtualInitialize(ATTRIBUTE,30,80,NORM);
  8056.     WindowOpen(w);
  8057.     WindowDisplay(w,1,NOEFFECT);
  8058.     VirtualWriteString(vw,"Hello World!!",1,1);
  8059.     VirtualWriteAttributes(vw,buf,1,1,13);  /* Writes alternating NORM and
  8060.                                                REVERSE attributes */
  8061.     WindowAssignToVirtual(w,vw,1,1);
  8062.   }
  8063.  
  8064.  
  8065.   The return values for VirtualWriteAttributes() are the same as
  8066.   VirtualWriteStringAttr().
  8067.  
  8068.  
  8069.  
  8070.  
  8071.  Page 133                     The C Window Library                    Page 133
  8072.  
  8073.   VirtualWriteCharAndAttr()
  8074.   -------------------------
  8075.  
  8076.   The VirtualWriteCharAndAttr() function writes a string of character/attribute
  8077.   pairs to a virtual window.  Use this function if you have created a string of
  8078.   character/attribute pairs, and want to output them easily.  The string
  8079.   consists of character and attributes in the following manner:
  8080.  
  8081.            char-attr-char-attr...
  8082.  
  8083.   Each character is followed by its corresponding video attribute.
  8084.   Here is the prototype:
  8085.  
  8086.   int VirtualWriteCharAndAttr(VWPOINTER vw, char *buffer, unsigned row,
  8087.                               unsigned col, unsigned length)
  8088.  
  8089.   The first argument is the virtual window. The second is the buffer where the
  8090.   character and attributes are stored.  The third and fourth is the (row,col)
  8091.   position in the virtual window to write, and the length argument is the
  8092.   number of character/attribute pairs from the buffer to write.  Please note
  8093.   the difference in the meaning of the length argument in this function as
  8094.   opposed to its use in the preceding functions.
  8095.  
  8096.   If the virtual window is NOATTRIBUTE, nothing is written to the virtual
  8097.   window.
  8098.  
  8099.   Example:
  8100.  
  8101.   #include "window.h"
  8102.   #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  8103.  
  8104.   WPOINTER w;
  8105.   VWPOINTER vw;
  8106.   char buf[26];
  8107.   char *str = "Hello World!!";
  8108.   main()
  8109.   {
  8110.     int i;
  8111.     WindowInitializeSystem();
  8112.     WindowSaveInitial(0);
  8113.     w = WindowInitialize(BORDER,1,1,20,10,NORM,NORM,SINGLEBOX);
  8114.     vw = VirtualInitialize(ATTRIBUTE,30,80,NORM);
  8115.     WindowOpen(w);
  8116.     WindowDisplay(w,1,NOEFFECT);
  8117.  
  8118.     for (i=0;i<26;i+=2,str++)
  8119.     {
  8120.       buf[i] = *str;
  8121.       buf[i+1] = NORM;
  8122.     }
  8123.     VirtualWriteCharAndAttr(vw,buf,1,1,13);
  8124.     WindowAssignToVirtual(w,vw,1,1);
  8125.   }
  8126.  
  8127.  Page 134                     The C Window Library                    Page 134
  8128.  
  8129.   The return values for VirtualWriteCharAndAttr() are the same as
  8130.   VirtualWriteStringAttr().
  8131.  
  8132.  
  8133.  
  8134.   VirtualWriteRepeatAttribute()
  8135.   -----------------------------
  8136.  
  8137.   The VirtualWriteRepeatAttribute() function writes an attribute a specified
  8138.   number of times to a virtual window.  Here is a prototype:
  8139.  
  8140.  
  8141.   int VirtualWriteRepeatAttribute(VWPOINTER vw, int attr, unsigned row,
  8142.                                   unsigned col, int count)
  8143.  
  8144.   The attr argument is the attribute to use.  The count argument specifies the
  8145.   number of times to write the attribute attr to the virtual window starting at
  8146.   (row,col).  If the virtual window is NOATTRIBUTE, this function returns an
  8147.   error.
  8148.  
  8149.  
  8150.   Example:
  8151.  
  8152.   #include "window.h"
  8153.   #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  8154.   #define REVERSE CREATE_VIDEO_ATTRIBUTE(white,black)
  8155.  
  8156.   WPOINTER w;
  8157.   VWPOINTER vw;
  8158.   main()
  8159.   {
  8160.     WindowInitializeSystem();
  8161.     WindowSaveInitial(0);
  8162.     w = WindowInitialize(BORDER,1,1,20,10,NORM,NORM,SINGLEBOX);
  8163.     vw = VirtualInitialize(ATTRIBUTE,30,80,NORM);
  8164.     WindowOpen(w);
  8165.     WindowDisplay(w,1,NOEFFECT);
  8166.     VirtualWriteString(vw,"Hello World!!",1,1);
  8167.     VirtualWriteRepeatAttribute(vw,REVERSE,1,1,13);
  8168.     WindowAssignToVirtual(w,vw,1,1);
  8169.   }
  8170.  
  8171.  
  8172.   The example above illustrates that the VirtualWriteRepeatAttribute() writes
  8173.   the REVERSE attribute 13 times starting at row 1, column 1 of the
  8174.   virtual window w.
  8175.  
  8176.   The return values for VirtualWriteRepeatAttribute() are the same as
  8177.   VirtualWriteStringAttr().
  8178.  
  8179.  
  8180.  
  8181.  
  8182.  
  8183.  Page 135                     The C Window Library                    Page 135
  8184.  
  8185.   VirtualWriteRepeatCharacter()
  8186.   -----------------------------
  8187.  
  8188.   The VirtualWriteRepeatCharacter() function writes a character a specified
  8189.   number of times to a virtual window.  Here is a prototype:
  8190.  
  8191.  
  8192.   int VirtualWriteRepeatCharacter(WPOINTER w, int ch, int row, int col,
  8193.                                   int count)
  8194.  
  8195.  
  8196.   The count argument is the character to use.  The count argument specifies the
  8197.   number of times to write the character ch to the virtual window starting at
  8198.   (row,col).
  8199.  
  8200.   Example:
  8201.  
  8202.   #include "window.h"
  8203.   #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  8204.  
  8205.   VWPOINTER vw;
  8206.   WPOINTER w;
  8207.  
  8208.   main()
  8209.   {
  8210.     WindowInitializeSystem();
  8211.     WindowSaveInitial(0);
  8212.     w = WindowInitialize(BORDER,1,1,20,10,NORM,NORM,SINGLEBOX);
  8213.     vw = VirtualInitialize(NOATTRIBUTE,30,80,0);
  8214.     WindowOpen(w);
  8215.     WindowDisplay(w,1,NOEFFECT);
  8216.     VirtualWriteRepeatCharacter(vw,'a',1,1,5);
  8217.     VirtualWriteRepeatCharacter(vw,'b',2,1,5);
  8218.     VirtualWriteRepeatCharacter(vw,'c',3,1,5);
  8219.     WindowAssignToVirtual(w,vw,1,1);
  8220.   }
  8221.  
  8222.  
  8223.   The example above illustrates that the VirtualWriteRepeatCharacter() writes
  8224.   the letter 'a', 'b', and 'c' 5 times on rows 1, 2, and 3 respectively.
  8225.  
  8226.   The return values for VirtualWriteRepeatCharacter() are the same as
  8227.   VirtualWriteString().
  8228.  
  8229.  
  8230.  
  8231.  
  8232.  
  8233.  
  8234.  
  8235.  
  8236.  
  8237.  
  8238.  
  8239.  Page 136                     The C Window Library                    Page 136
  8240.  
  8241.   Formatted Write Functions
  8242.   -------------------------
  8243.  
  8244.  
  8245.   Format String
  8246.   -------------
  8247.  
  8248.   These functions write formatted output to virtual windows just like the
  8249.   printf() function.  There are two functions that do this, namely
  8250.   VirtualPrintf() and VirtualPrintfAttr().  These functions use a format
  8251.   string that is similar to the format string found in printf().  For example,
  8252.   %d, %s, %lf, etc. and most of the escape sequences are supported.  The list
  8253.   of escape sequences supported are as follows:
  8254.  
  8255.                         \n - newline
  8256.                         \t - tab
  8257.                         \r - carriage return
  8258.                         \x - hexadecimal
  8259.  
  8260.  
  8261.   Where Output is Placed
  8262.   ----------------------
  8263.  
  8264.   The row and column of where the string will be written is determined by the
  8265.   virtual window's logical cursor.  The logical cursor is advanced by both of
  8266.   these functions to one column position after the last character is printed.
  8267.   If you want to start at a particular row and column of the window, you must
  8268.   move the cursor yourself by calling the VirtualMoveCursor() function.  This
  8269.   function is explained in the MOVING THE LOGICAL CURSOR section.
  8270.  
  8271.   When the virtual window is first initialized using VirtualInitialize(), the
  8272.   logical cursor is automatically moved to (1,1) of the virtual window.
  8273.  
  8274.  
  8275.  
  8276.   VirtualSetWrap()
  8277.   ----------------
  8278.  
  8279.   With these functions, any text that will exceed the boundaries of the window
  8280.   will be wrapped to the next line.  If the output will exceed the last row of
  8281.   the window, the window is automatically scrolled up by one line.  This is the
  8282.   default action to take when characters exceed the right edge of the
  8283.   virtual window.  If you want the output clipped instead of wrapped, you must
  8284.   set the virtual window's wrap flag using the VirtualSetWrap() function.
  8285.  
  8286.   The VirtualSetWrap() function sets the virtual window's wrap flag to either
  8287.   on or off.  Here is the prototype:
  8288.  
  8289.               int VirtualSetWrap(VWPOINTER vw, int option)
  8290.  
  8291.   The second argument will be 0 if you want to turn the wrap flag off, or 1 if
  8292.   you want to turn it on.  If the wrap flag is off, the output generated by
  8293.  
  8294.  
  8295.  Page 137                     The C Window Library                    Page 137
  8296.  
  8297.   VirtualPrintf() and VirtualPrintfAttr() will be terminated when the right edge
  8298.   of the window is reached.  If the wrap flag is on, the output is wrapped to
  8299.   the next line when the right edge is reached.  Unlike regular windows, the
  8300.   output is not scrolled if the last line of the virtual window is reached.
  8301.  
  8302.   You can set the wrap flag to a virtual window at any time.
  8303.  
  8304.  
  8305.  
  8306.   VirtualPrintf()
  8307.   --------------
  8308.  
  8309.   The VirtualPrintf() function writes formatted output to the virtual window.
  8310.   Here is the prototype:
  8311.  
  8312.             int VirtualPrintf(VWPOINTER vw, char *format [,arg1,...])
  8313.  
  8314.   The first argument is the virtual window.  The second argument is a format
  8315.   string.  The rest of the arguments are optional arguments that are written to
  8316.   the virtual window.
  8317.  
  8318.  
  8319.   Example:
  8320.  
  8321.   #include "window.h"
  8322.   #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  8323.  
  8324.   WPOINTER w;
  8325.   VWPOINTER vw;
  8326.   int i = 3;
  8327.   double j = 5.6;
  8328.  
  8329.   main()
  8330.   {
  8331.     WindowInitializeSystem();
  8332.     WindowSaveInitial(0);
  8333.     w = WindowInitialize(BORDER,1,1,30,10,NORM,NORM,SINGLEBOX);
  8334.     vw = VirtualInitialize(NOATTRIBUTE,30,80,0);
  8335.     WindowOpen(w);
  8336.     WindowDisplay(w,1,NOEFFECT);
  8337.     WindowAssignToVirtual(w,vw,1,1);
  8338.     VirtualPrintf(vw,"3+2 is equal to %d\n",3+2);
  8339.     GET_KEY();
  8340.     VirtualPrintf(vw,"i is equal to %d\nj is equal to %lf\n",i,j);
  8341.   }
  8342.  
  8343.  
  8344.   The above example illustrates how VirtualPrintf() is used to print formatted
  8345.   strings to a virtual window.
  8346.  
  8347.   The return values for VirtualPrintf() are the same as VirtualWriteString().
  8348.  
  8349.  
  8350.  
  8351.  Page 138                     The C Window Library                    Page 138
  8352.  
  8353.   VirtualPrintfAttr()
  8354.   -------------------
  8355.  
  8356.   The VirtualPrintfAttr() function writes formatted output to the virtual
  8357.   window.  The difference between VirtualPrintf() and VirtualPrintfAttr() is
  8358.   that VirtualPrintfAttr() uses a video attribute specified as an argument.
  8359.   Here is the prototype:
  8360.  
  8361.      int VirtualPrintfAttr(VWPOINTER vw, int attr, char *format [,arg1,...])
  8362.  
  8363.   The first argument is the virtual window.  The second argument is the video
  8364.   attribute to use.  The third argument is the format string.  The rest of the
  8365.   arguments are optional arguments that are written to the virtual window.
  8366.   If the virtual window is NOATTRIBUTE, only the string is written to the
  8367.   window.
  8368.  
  8369.   Example:
  8370.  
  8371.   #include "window.h"
  8372.   #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  8373.   #define REVERSE CREATE_VIDEO_ATTRIBUTE(white,black)
  8374.  
  8375.   WPOINTER w;
  8376.   VWPOINTER vw;
  8377.   int i = 3;
  8378.   double j = 5.6;
  8379.  
  8380.   main()
  8381.   {
  8382.     WindowInitializeSystem();
  8383.     WindowSaveInitial(0);
  8384.     w = WindowInitialize(BORDER,1,1,30,10,NORM,NORM,SINGLEBOX);
  8385.     vw = VirtualInitialize(ATTRIBUTE,30,80,NORM);
  8386.     WindowOpen(w);
  8387.     WindowDisplay(w,1,NOEFFECT);
  8388.     WindowAssignToVirtual(w,vw,1,1);
  8389.     VirtualPrintfAttr(vw,REVERSE,"3+2 is equal to %d\n",3+2);
  8390.     GET_KEY();
  8391.     VirtualPrintfAttr(vw,REVERSE,"i is equal to %d\nj is equal to %lf\n",i,j);
  8392.   }
  8393.  
  8394.  
  8395.   The above example illustrates how VirtualPrintfAttr() is used to print
  8396.   formatted strings.
  8397.  
  8398.   The return values for VirtualPrintfAttr() are the same as
  8399.   VirtualWriteStringAttr().
  8400.  
  8401.  
  8402.  
  8403.  
  8404.  
  8405.  
  8406.  
  8407.  Page 139                     The C Window Library                    Page 139
  8408.  
  8409.             READING CHARACTERS AND ATTRIBUTES FROM VIRTUAL WINDOWS
  8410.             ------------------------------------------------------
  8411.  
  8412.  
  8413.   With The C Window Library, you can read the contents of a virtual window into
  8414.   a character buffer.  These functions provide the programmer with the contents
  8415.   of the virtual window at any time.  The functions to perform this are
  8416.   VirtualReadAttributes(), VirtualReadCharacters() and VirtualReadCharAndAttr().
  8417.  
  8418.  
  8419.  
  8420.   VirtualReadCharacters()
  8421.   -----------------------
  8422.  
  8423.   The VirtualReadCharacters() function reads the characters from a virtual
  8424.   window into a buffer.  Here is the prototype.
  8425.  
  8426.   int VirtualReadCharacters(VWPOINTER vw, char *buffer, unsigned row,
  8427.                             unsigned col, unsigned length)
  8428.  
  8429.   The first argument is the virtual window.  The second argument is the buffer
  8430.   to store the characters in.  The third and fourth arguments are the (row,col)
  8431.   position in the virtual window to start reading from.  The last argument is
  8432.   the number of characters to read.
  8433.  
  8434.   You must make sure that buffer has enough room to hold all of the characters
  8435.   read in.
  8436.  
  8437.  
  8438.   Example:
  8439.  
  8440.   #include "window.h"
  8441.   #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  8442.  
  8443.   VWPOINTER vw;
  8444.   char buf[14] = {0};      /* Null all elements of buf */
  8445.  
  8446.   main()
  8447.   {
  8448.     int i;
  8449.     WindowInitializeSystem();
  8450.     WindowSaveInitial(0);
  8451.     vw = VirtualInitialize(NOATTRIBUTE,10,80,NORM);
  8452.     VirtualWriteString(vw,"Hello World!!",1,1);/* Write String */
  8453.     VirtualReadCharacters(vw,buf,1,1,13);      /* Read characters */
  8454.   }
  8455.  
  8456.   The example above illustrates the use of VirtualReadCharacters(), which reads
  8457.   the virtual window's contents starting at (1,1).  This happens to be the
  8458.   string "Hello World!!".
  8459.  
  8460.   If the length exceeds the right edge of the virtual window,
  8461.   VirtualReadCharacters() will read up to the right edge of the virtual window.
  8462.  
  8463.  Page 140                     The C Window Library                    Page 140
  8464.  
  8465.   If there are no errors, VirtualReadCharacters() returns NO_ERROR.
  8466.  
  8467.   If there are errors, VirtualReadCharacters() returns one of the following:
  8468.  
  8469.   BAD_V_WINDOW if the virtual window does not exist.
  8470.  
  8471.   V_WINDOW_BOUND if the row or column specified in the virtual window is out of
  8472.   bounds.
  8473.  
  8474.  
  8475.  
  8476.  
  8477.  
  8478.   VirtualReadAttributes()
  8479.   ----------------------
  8480.  
  8481.   The VirtualReadAttributes() function reads the attributes from a virtual
  8482.   window into a buffer.  Here is the prototype.
  8483.  
  8484.   int VirtualReadAttributes(VWPOINTER w, char *buffer, unsigned row,
  8485.                             unsigned col, unsigned length)
  8486.  
  8487.   The first argument is the virtual window.  The second argument is the buffer
  8488.   to store the attributes in.  The third and fourth arguments are the (row,col)
  8489.   position in the virtual window to start reading from.  The last argument is
  8490.   the number of attributes to read.  If the virtual window is NOATTRIBUTE,
  8491.   nothing is read.
  8492.  
  8493.   You must make sure that buffer has enough room to hold all of the attributes
  8494.   read in.
  8495.  
  8496.  
  8497.   Example:
  8498.  
  8499.   #include "window.h"
  8500.   #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  8501.  
  8502.   VWPOINTER vw;
  8503.   char buf[14] = {0};      /* Null all elements of buf */
  8504.  
  8505.   main()
  8506.   {
  8507.     int i;
  8508.     WindowInitializeSystem();
  8509.     WindowSaveInitial(0);
  8510.     vw = VirtualInitialize(ATTRIBUTE,10,80,NORM);
  8511.     VirtualReadAttributes(vw,buf,1,1,13);      /* Read attributes */
  8512.   }
  8513.  
  8514.   The example above illustrates the use of VirtualReadAttributes(), which reads
  8515.   the virtual window's attribute contents starting at (1,1) of the virtual
  8516.   window.
  8517.  
  8518.  
  8519.  Page 141                     The C Window Library                    Page 141
  8520.  
  8521.   If the length exceeds the right edge of the virtual window,
  8522.   VirtualReadAttributes() will read up to the right edge of the virtual window.
  8523.  
  8524.  
  8525.   If there are no errors, VirtualReadAttributes() returns NO_ERROR.
  8526.  
  8527.   If there are errors, VirtualReadAttributes() returns one of the following:
  8528.  
  8529.   BAD_V_WINDOW if the virtual window does not exist.
  8530.  
  8531.   V_WINDOW_BOUND if the row or column specified in the virtual window is out of
  8532.   bounds.
  8533.  
  8534.   NO_ATTRIB if the virtual window is NOATTRIBUTE.
  8535.  
  8536.  
  8537.  
  8538.  
  8539.   VirtualReadCharAndAttr()
  8540.   ------------------------
  8541.  
  8542.   The VirtualReadCharAndAttr() function reads character/attribute pairs from a
  8543.   virtual window into a buffer.  Here is the prototype.
  8544.  
  8545.   int VirtualReadCharAndAttr(VWPOINTER w, char *buffer, unsigned row,
  8546.                              unsigned col, unsigned length)
  8547.  
  8548.   The first argument is the virtual window.  The second argument is the buffer
  8549.   to store the character/attribute pairs in.  The third and fourth arguments
  8550.   are the (row,col) position in the virtual window to start reading from.  The
  8551.   last argument is the number of character/attribute pairs to read.  If the
  8552.   window is NOATTRIBUTE, nothing is read.
  8553.  
  8554.   You must make sure that buffer has enough room to hold all of the
  8555.   character/attribute pairs read in.
  8556.  
  8557.   Example:
  8558.  
  8559.   #include "window.h"
  8560.   #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  8561.  
  8562.   VWPOINTER vw;
  8563.   char buf[27] = {0};      /* Null all elements of buf */
  8564.  
  8565.   main()
  8566.   {
  8567.     int i;
  8568.     WindowInitializeSystem();
  8569.     WindowSaveInitial(0);
  8570.     vw = VirtualInitialize(ATTRIBUTE,10,80,NORM);
  8571.     VirtualWriteString(vw,"Hello World!!",1,1);/* Write String */
  8572.     VirtualReadCharAndAttr(vw,buf,1,1,13);      /* Read character/attributes */
  8573.   }
  8574.  
  8575.  Page 142                     The C Window Library                    Page 142
  8576.  
  8577.   The example above illustrates the use of VirtualReadCharAndAttr(), which reads
  8578.   the virtual window's character/attribute contents starting at (1,1) of the
  8579.   virtual window.  This happens to be the characters/attributes of the string
  8580.   "Hello World!!".
  8581.  
  8582.   If the length exceeds the right edge of the virtual window,
  8583.   VirtualReadCharAndAttr() will read up to the right edge of the virtual window.
  8584.  
  8585.  
  8586.   If there are no errors, VirtualReadCharAndAttr() returns NO_ERROR.
  8587.  
  8588.   If there are errors, VirtualReadCharAndAttr() returns one of the following:
  8589.  
  8590.   BAD_V_WINDOW if the virtual window does not exist.
  8591.  
  8592.   V_WINDOW_BOUND if the row or column specified in the virtual window is out of
  8593.   bounds.
  8594.  
  8595.   NO_ATTRIB if the virtual window is NOATTRIBUTE.
  8596.  
  8597.  
  8598.  
  8599.  
  8600.  
  8601.  
  8602.  
  8603.  
  8604.  
  8605.  
  8606.  
  8607.  
  8608.  
  8609.  
  8610.  
  8611.  
  8612.  
  8613.  
  8614.  
  8615.  
  8616.  
  8617.  
  8618.  
  8619.  
  8620.  
  8621.  
  8622.  
  8623.  
  8624.  
  8625.  
  8626.  
  8627.  
  8628.  
  8629.  
  8630.  
  8631.  Page 143                     The C Window Library                    Page 143
  8632.  
  8633.                           REPOSITIONING THE VIEWPORT
  8634.                           --------------------------
  8635.  
  8636.   A viewport can be repositioned anywhere on the virtual window.  This allows
  8637.   to view different parts of the virtual window.
  8638.  
  8639.  
  8640.   WindowPositionViewport()
  8641.   ------------------------
  8642.  
  8643.   The WindowPositionViewport() function positions the viewport to a new
  8644.   location on the virtual window it is associated with.  Here is the prototype:
  8645.  
  8646.  
  8647.      int WindowPositionViewport(WPOINTER w, unsigned row, unsigned col)
  8648.  
  8649.   The first argument is the viewport window.  The second argument and third
  8650.   arguments are is the (row,col) position of the virtual window associated with
  8651.   w.  This position will be where the upper left hand corner of the viewport's
  8652.   text area will be placed.
  8653.  
  8654.  
  8655.   Example:
  8656.  
  8657.   #include <stdio.h>
  8658.   #include <string.h>
  8659.   #include "window.h"
  8660.  
  8661.   #define NORM  CREATE_VIDEO_ATTRIBUTE(black,white)
  8662.  
  8663.                     /* define filename characters */
  8664.   #define FILENAMECHARS  "25[A-Za-z0-9!@#$%/^&()+=_/-{}/[/]`~/.\\:]"
  8665.  
  8666.   VWPOINTER vw;          /* virtual window pointer */
  8667.   WPOINTER w;            /* Window pointer */
  8668.   char filename[26];
  8669.   FILE *infile;          /* input file handle */
  8670.  
  8671.   main()
  8672.   {
  8673.     unsigned int i,j,row,col;
  8674.     WindowInitializeSystem();
  8675.     WindowSaveInitial(0);
  8676.  
  8677.     /* set up a Type 0 virtual window */
  8678.     vw = VirtualInitialize(NOATTRIBUTE,  /* virtual window type number */
  8679.                            200,      /* Number of rows */
  8680.                            80,      /* Number of cols */
  8681.                            0);      /* Attribute      */
  8682.  
  8683.  
  8684.  
  8685.  
  8686.  
  8687.  Page 144                     The C Window Library                    Page 144
  8688.  
  8689.     /* set up viewport window */
  8690.     w = WindowInitialize(BORDER,1,1,78,12,NORM,NORM,SINGLEBOX);
  8691.     WindowOpen(w);
  8692.     WindowDisplay(w,1,NOEFFECT);
  8693.  
  8694.     /* read a file name */
  8695.     read_file();
  8696.  
  8697.     /* display file in viewport */
  8698.     WindowAssignToVirtual(w,vw,1,1);    /* Assign viewport to virtual window */
  8699.  
  8700.     row = col = 1;
  8701.     flush_keyboard_flag = TRUE;        /* Set keyboard flush to TRUE */
  8702.     while (1)
  8703.     {
  8704.       switch (GET_KEY())    /* Keep getting keys until ESCAPE key is hit */
  8705.       {
  8706.          case UARROW:      /* Move viewport up 1 line */
  8707.  
  8708.            if (row > 1)
  8709.              WindowPositionViewport(w,--row,col);
  8710.          break;
  8711.          case DARROW:      /* Move viewport down 1 line */
  8712.            if (row < 189)
  8713.              WindowPositionViewport(w,++row,col);
  8714.          break;
  8715.          case LARROW:      /* Move viewport left 1 line */
  8716.            if (col > 1)
  8717.              WindowPositionViewport(w,row,--col);
  8718.          break;
  8719.          case RARROW:      /* Move viewport right 1 line */
  8720.            if (col < 69)
  8721.              WindowPositionViewport(w,row,++col);
  8722.          break;
  8723.          case ESC:         /* End program */
  8724.            close_all();
  8725.          break;
  8726.       }
  8727.     }
  8728.   }
  8729.  
  8730.  
  8731.  
  8732.  
  8733.  
  8734.  
  8735.  
  8736.  
  8737.  
  8738.  
  8739.  
  8740.  
  8741.  
  8742.  
  8743.  Page 145                     The C Window Library                    Page 145
  8744.  
  8745.   read_file()         /* Gets a filename and displays it in the window */
  8746.   {
  8747.      int ch;
  8748.      unsigned r = 1, c = 1;
  8749.      filename[0] = 0;
  8750.      WindowWriteString(w,"Please enter a file name: ",1,1);
  8751.      WindowGetString(w,1,27,filename,'_',0,40,0,FILENAMECHARS);
  8752.      if ((infile = fopen(filename,"r")) == NULL)
  8753.      {
  8754.        WindowMoveCursor(w,3,1);
  8755.        WindowPrintf(w,"File name %s does not exist\nPress a key to continue",
  8756.                 filename);
  8757.        GET_KEY();
  8758.        close_all();
  8759.      }
  8760.      else
  8761.      while(1)         /* Read characters into virtual window */
  8762.      {
  8763.        ch = fgetc(infile);
  8764.        if (feof(infile))
  8765.          break;
  8766.        if (ch != '\n')
  8767.          VirtualWriteRepeatCharacter(vw,ch,r,c++,1);
  8768.        else
  8769.        {
  8770.          r++;
  8771.          c=1;
  8772.  
  8773.        }
  8774.      }
  8775.      fclose(infile);
  8776.   }
  8777.  
  8778.  
  8779.  
  8780.   close_all()
  8781.   {
  8782.     WindowClose(w,NOEFFECT);
  8783.     exit(0);
  8784.   }
  8785.  
  8786.  
  8787.   The above example reads in a text file and uses WindowPositionViewport() to
  8788.   move left, right, up, or down.  There is no checking to see if you have
  8789.   scrolled past the end of the file.
  8790.  
  8791.   The read_file() function reads a file and copies each character in the file to
  8792.   the virtual window called vw.
  8793.  
  8794.   In the main program, the global variable flush_keyboard_flag, defined in the
  8795.   IMPORTANT GLOBAL VARIABLES section, is set to TRUE.  When flush_keyboard is
  8796.   TRUE, the keyboard buffer is flushed before any incoming keystrokes are
  8797.   accepted.  Otherwise the keyboard buffer is not flushed.
  8798.  
  8799.  Page 146                     The C Window Library                    Page 146
  8800.  
  8801.   In the while(1) loop of the main program, the constants UARROW, DARROW,
  8802.   LARROW, and RARROW, stands for the up, down, left, and the right arrow keys on
  8803.   the keypad, respectively.  The constants UARROW, DARROW, LARROW, and RARROW
  8804.   are defined in keycodes.h.  Depending on the key that is hit, the viewport is
  8805.   repositioned to point to a new row or column.  The call to
  8806.   WindowPositionViewport() has three arguments.  The first is the pointer to the
  8807.   viewport window, the second and the third are the row and the column of the
  8808.   virtual window to place the upper left hand corner of the viewport.
  8809.  
  8810.   There is minimal bounds checking in the above example, however you can enhance
  8811.   it by putting in more bounds checking and by implementing a page down, or page
  8812.   up function.
  8813.  
  8814.  
  8815.   If there are no errors, WindowPositionViewport() returns NO_ERROR.
  8816.   If there are errors, WindowPositionViewport() will return one of the
  8817.   following values:
  8818.  
  8819.   BAD_WINDOW if the viewport window does not exist.
  8820.  
  8821.   BAD_V_WINDOW if the viewport is pointing to a virtual window that does not
  8822.   exist.
  8823.  
  8824.   V_WINDOW_BOUND if the row and col arguments are out of bounds of the virtual
  8825.   window.
  8826.  
  8827.  
  8828.  
  8829.  
  8830.  
  8831.  
  8832.  
  8833.  
  8834.  
  8835.  
  8836.  
  8837.  
  8838.  
  8839.  
  8840.  
  8841.  
  8842.  
  8843.  
  8844.  
  8845.  
  8846.  
  8847.  
  8848.  
  8849.  
  8850.  
  8851.  
  8852.  
  8853.  
  8854.  
  8855.  Page 147                     The C Window Library                    Page 147
  8856.  
  8857.                              SCROLLING THE VIEWPORTS
  8858.                              -----------------------
  8859.  
  8860.   Viewports can have its display scrolled left, right, up, or down using the
  8861.   WindowScrollViewport() function described below.
  8862.  
  8863.  
  8864.   WindowScrollViewport()
  8865.   ---------------------
  8866.  
  8867.   This functions scrolls the viewport specific number of characters.
  8868.   Here is the prototype:
  8869.  
  8870.       int WindowScrollViewport(WPOINTER w, unsigned num, int direction)
  8871.  
  8872.   The first argument is the viewport and the second argument is the number of
  8873.   characters to scroll.  The last argument is the direction to scroll.  This
  8874.   direction can be UP, DOWN, LEFT, or RIGHT.
  8875.  
  8876.  
  8877.   Example:
  8878.  
  8879.  
  8880.   #include <stdio.h>
  8881.   #include <string.h>
  8882.   #include "window.h"
  8883.  
  8884.   #define NORM  CREATE_VIDEO_ATTRIBUTE(black,white)
  8885.  
  8886.                     /* define filename characters */
  8887.   #define FILENAMECHARS  "25[A-Za-z0-9!@#$%/^&()+=_/-{}/[/]`~/.\\:]"
  8888.  
  8889.   VWPOINTER vw;          /* virtual window pointer */
  8890.   WPOINTER w;            /* Window pointer */
  8891.   char filename[26];
  8892.   FILE *infile;          /* input file handle */
  8893.  
  8894.   main()
  8895.   {
  8896.     unsigned int i,j,row,col;
  8897.     WindowInitializeSystem();
  8898.     WindowSaveInitial(0);
  8899.     /* set up a Type 0 virtual window */
  8900.     vw = VirtualInitialize(NOATTRIBUTE,  /* virtual window type number */
  8901.                            200,      /* Number of rows */
  8902.                            80,      /* Number of cols */
  8903.                            0);      /* Attribute      */
  8904.  
  8905.     /* set up viewport window */
  8906.     w = WindowInitialize(BORDER,1,1,78,12,NORM,NORM,SINGLEBOX);
  8907.     WindowOpen(w);
  8908.     WindowDisplay(w,1,NOEFFECT);
  8909.  
  8910.  
  8911.  Page 148                     The C Window Library                    Page 148
  8912.  
  8913.     /* read a file name */
  8914.     read_file();
  8915.  
  8916.     /* display file in viewport */
  8917.     WindowAssignToVirtual(w,vw,1,1);   /* Assign viewport to virtual window */
  8918.     flush_keyboard_flag = TRUE;        /* Set keyboard flush to TRUE */
  8919.     while (1)
  8920.     {
  8921.       switch (GET_KEY())    /* Keep getting keys until ESCAPE key is hit */
  8922.       {
  8923.          case UARROW:      /* Move viewport up 1 line */
  8924.            WindowScrollViewport(w,1,UP);
  8925.          break;
  8926.          case DARROW:      /* Move viewport down 1 line */
  8927.            WindowScrollViewport(w,1,DOWN);
  8928.          break;
  8929.          case LARROW:      /* Move viewport left 1 line */
  8930.            WindowScrollViewport(w,1,LEFT);
  8931.          break;
  8932.          case RARROW:      /* Move viewport right 1 line */
  8933.            WindowScrollViewport(w,1,RIGHT);
  8934.          break;
  8935.          case ESC:         /* End program */
  8936.            close_all();
  8937.          break;
  8938.       }
  8939.     }
  8940.   }
  8941.  
  8942.   read_file()         /* Gets a filename and displays it in the window */
  8943.   {
  8944.      int ch;
  8945.      unsigned r = 1, c = 1;
  8946.      filename[0]=0;
  8947.      WindowWriteString(w,"Please enter a file name: ",1,1);
  8948.      WindowGetString(w,1,27,filename,'_',0,40,0,FILENAMECHARS);
  8949.      if ((infile = fopen(filename,"r")) == NULL)
  8950.      {
  8951.        WindowMoveCursor(w,3,1);
  8952.        WindowPrintf(w,"File name %s does not exist\nPress a key to continue",
  8953.                 filename);
  8954.        GET_KEY();
  8955.        close_all();
  8956.      }
  8957.      else
  8958.      while(1)         /* Read characters into virtual window */
  8959.      {
  8960.        ch = fgetc(infile);
  8961.        if (feof(infile))
  8962.          break;
  8963.        if (ch != '\n')
  8964.          VirtualWriteRepeatCharacter(vw,ch,r,c++,1);
  8965.  
  8966.  
  8967.  Page 149                     The C Window Library                    Page 149
  8968.  
  8969.        else
  8970.        {
  8971.          r++;
  8972.          c=1;
  8973.  
  8974.        }
  8975.      }
  8976.      fclose(infile);
  8977.   }
  8978.  
  8979.  
  8980.  
  8981.   close_all()
  8982.   {
  8983.     WindowClose(w,NOEFFECT);
  8984.     exit(0);
  8985.   }
  8986.  
  8987.  
  8988.   The example above is the same as the example for the
  8989.   WindowPositionViewport() function, except that the call to
  8990.   WindowPositionViewport() is replaced with the appropriate
  8991.   WindowScrollViewport() call.
  8992.  
  8993.  
  8994.   For WindowScrollViewport(), the window is never scrolled if the scroll will
  8995.   result in the upper left hand corner of the viewport being out of bounds of
  8996.   the virtual window.  For example, you cannot scroll left 1 character if the
  8997.   viewport is located at (1,1) of the virtual window, similarly you cannot
  8998.   scroll right if the virtual window has a maximum of 80 characters and the
  8999.   upper left hand corner of the viewport is situated at (1,80).  The same
  9000.   restrictions apply for scrolling up and down.
  9001.  
  9002.   If there are no errors, all of the WindowScrollViewport() functions will
  9003.   return NO_ERROR.
  9004.  
  9005.   If there are errors, these functions will return the following value:
  9006.  
  9007.   V_WINDOW_BOUND if the scroll will cause the upper left hand position of the
  9008.   viewport to be out of bounds.
  9009.  
  9010.  
  9011.  
  9012.  
  9013.  
  9014.  
  9015.  
  9016.  
  9017.  
  9018.  
  9019.  
  9020.  
  9021.  
  9022.  
  9023.  Page 150                     The C Window Library                    Page 150
  9024.  
  9025.                    WRITING VIRTUAL WINDOW CONTENTS TO A FILE
  9026.                    -----------------------------------------
  9027.  
  9028.   The C Window Library allows you to print the contents of a virtual window
  9029.   using the VirtualWriteTextToFile() function.
  9030.  
  9031.  
  9032.  
  9033.   VirtualWriteTextToFile()
  9034.   ------------------------
  9035.  
  9036.   The VirtualWriteTextToFile() function allows you to print the contents of a
  9037.   virtual window to a file.  Here is the prototype:
  9038.  
  9039.   int VirtualWriteTextToFile(VWPOINTER vw, char *filename, int mode)
  9040.  
  9041.  
  9042.   The first argument is the virtual window.  The second argument is the file
  9043.   name.  This file can be any of the DOS filenames ("con", "prn", "aux", etc.).
  9044.   The file specified by filename must be closed before calling
  9045.   VirtualWriteTextToFile(), and the file handle is automatically closed before
  9046.   exiting VirtualWriteTextToFile().
  9047.  
  9048.   The last argument is the mode switch.  If mode is 1, a newline ('\n') is
  9049.   written to the file after each line of the virtual window written to the
  9050.   file.  If mode is 0, no newline character is written.  When mode 0 is chosen,
  9051.   the file is open in binary mode, else it is open in text mode.
  9052.  
  9053.   Example:
  9054.  
  9055.   #include "window.h"
  9056.  
  9057.   VWPOINTER vw;
  9058.   char *filename = "wintext";
  9059.   char *filename2 = "wintext2";
  9060.  
  9061.   main()
  9062.   {
  9063.     int i;
  9064.     WindowInitializeSystem();
  9065.     vw = VirtualInitialize(NOATTRIBUTE,30,80,0);
  9066.     for (i=1;i<=10;i++)
  9067.       VirtualWriteString(vw,"Hello World!!",i,1);
  9068.     VirtualWriteTextToFile(vw,filename,1);  /* use newlines */
  9069.     VirtualWriteTextToFile(vw,filename2,0); /* no newlines */
  9070.   }
  9071.  
  9072.   The example above illustrates two calls to VirtualWriteTextToFile().  The
  9073.   first call writes the contents of the virtual window vw to a file called
  9074.   "wintext".  Note that the mode parameter for the first call is 1.  This will
  9075.   cause '\n' to be written to the file for each line of the virtual window.
  9076.   The second call writes the virtual window text to a file call "wintest2",
  9077.   with the mode parameter being 0 (no '\n').
  9078.  
  9079.  Page 151                     The C Window Library                    Page 151
  9080.  
  9081.   Please note that VirtualWriteTextToFile() does not check if the file already
  9082.   exists, so be careful that you do not replace files that are important to
  9083.   you.
  9084.  
  9085.  
  9086.  
  9087.   If there are no errors, VirtualWriteTextToFile() returns NO_ERROR.
  9088.  
  9089.   If there are errors, VirtualWriteTextToFile() will return one of the
  9090.   following:
  9091.  
  9092.  
  9093.   BAD_V_WINDOW if the virtual window does not exist.
  9094.  
  9095.   FILE_CANT_OPEN if the file specified by filename cannot be open.
  9096.  
  9097.   FILE_CANT_CLOSE if the file specified by filename cannot be closed.
  9098.  
  9099.  
  9100.  
  9101.  
  9102.  
  9103.  
  9104.  
  9105.  
  9106.  
  9107.  
  9108.  
  9109.  
  9110.  
  9111.  
  9112.  
  9113.  
  9114.  
  9115.  
  9116.  
  9117.  
  9118.  
  9119.  
  9120.  
  9121.  
  9122.  
  9123.  
  9124.  
  9125.  
  9126.  
  9127.  
  9128.  
  9129.  
  9130.  
  9131.  
  9132.  
  9133.  
  9134.  
  9135.  Page 152                     The C Window Library                    Page 152
  9136.  
  9137.                            MOVING THE LOGICAL CURSOR
  9138.                            -------------------------
  9139.  
  9140.   You can move and get the position of the logical cursor in a virtual window.
  9141.  
  9142.  
  9143.  
  9144.   VirtualMoveCursor()
  9145.   -------------------
  9146.  
  9147.   The VirtualMoveCursor() function moves a virtual window's logical cursor to a
  9148.   new location.  Here is the prototype:
  9149.  
  9150.      int VirtualMoveCursor(VWPOINTER vw, unsigned row, unsigned col)
  9151.  
  9152.   The first argument is the virtual window, and the second and third arguments
  9153.   denote the new (row,col) position of the logical cursor.
  9154.  
  9155.   Example:
  9156.  
  9157.   #include "window.h"
  9158.  
  9159.   VWPOINTER vw;
  9160.  
  9161.   main()
  9162.   {
  9163.     int i;
  9164.     WindowInitializeSystem();
  9165.     vw = VirtualInitialize(NOATTRIBUTE,30,80,0);
  9166.     VirtualMoveCursor(vw,10,10);  /* Moves the logical cursor to row 10, column
  9167.                                      10 of the virtual window */
  9168.   }
  9169.  
  9170.   If there are no errors, VirtualMoveCursor() returns NO_ERROR.
  9171.   If there are errors, VirtualMoveCursor() returns one of the following values:
  9172.  
  9173.   BAD_V_WINDOW if the virtual window does not exist.
  9174.  
  9175.   V_WINDOW_BOUND if either the row or column specified is out of bounds.
  9176.  
  9177.  
  9178.  
  9179.  
  9180.   VirtualGetCursorPosition()
  9181.   --------------------------
  9182.  
  9183.   The VirtualGetCursorPosition() function gives the current row and column of
  9184.   the cursor in a virtual window.  Here is the prototype:
  9185.  
  9186.     int VirtualGetCursorPosition(VWPOINTER vw, unsigned *row, unsigned *col)
  9187.  
  9188.   The row and col arguments are pointers to unsigned integers that will contain
  9189.   the row and column of the cursor after VirtualGetCursorPosition() is called.
  9190.  
  9191.  Page 153                     The C Window Library                    Page 153
  9192.  
  9193.   Example:
  9194.  
  9195.   #include "window.h"
  9196.  
  9197.   VWPOINTER vw;
  9198.  
  9199.   main()
  9200.   {
  9201.     unsigned row,col;
  9202.     WindowInitializeSystem();
  9203.     vw = VirtualInitialize(NOATTRIBUTE,30,80,0);
  9204.     VirtualMoveCursor(vw,7,4);
  9205.     VirtualGetCursorPosition(vw,&row,&col);
  9206.   }
  9207.  
  9208.   If there are no errors, VirtualGetCursorPosition() returns NO_ERROR.
  9209.   If there are errors, VirtualGetCursorPosition() returns the following value:
  9210.  
  9211.   BAD_V_WINDOW if the window does not exist.
  9212.  
  9213.  
  9214.  
  9215.  
  9216.  
  9217.  
  9218.  
  9219.  
  9220.  
  9221.  
  9222.  
  9223.  
  9224.  
  9225.  
  9226.  
  9227.  
  9228.  
  9229.  
  9230.  
  9231.  
  9232.  
  9233.  
  9234.  
  9235.  
  9236.  
  9237.  
  9238.  
  9239.  
  9240.  
  9241.  
  9242.  
  9243.  
  9244.  
  9245.  
  9246.  
  9247.  Page 154                     The C Window Library                    Page 154
  9248.  
  9249.                            CLEARING VIRTUAL WINDOWS
  9250.                            ------------------------
  9251.  
  9252.  
  9253.   The C Window Library contains functions that clears the entire virtual
  9254.   window, or clears defined rectangular regions of the virtual window.
  9255.  
  9256.  
  9257.   VirtualClear()
  9258.   --------------
  9259.  
  9260.   The VirtualClear() function clears an entire virtual window to spaces.  Here
  9261.   is the prototype:
  9262.  
  9263.                       int VirtualClear(VWPOINTER vw)
  9264.  
  9265.   The only argument is the virtual window to clear.
  9266.  
  9267.   Example:
  9268.  
  9269.   #include "window.h"
  9270.   #define NORM  CREATE_VIDEO_ATTRIBUTE(black,white)
  9271.  
  9272.   VWPOINTER vw;
  9273.   WPOINTER w;
  9274.  
  9275.   main()
  9276.   {
  9277.     int i;
  9278.     WindowInitializeSystem();
  9279.     WindowSaveInitial(0);
  9280.     w = WindowInitialize(BORDER,1,1,20,10,NORM,NORM,SINGLEBOX);
  9281.     vw = VirtualInitialize(NOATTRIBUTE,30,80,NORM);
  9282.     WindowOpen(w);
  9283.     WindowDisplay(w,1,NOEFFECT);
  9284.     WindowAssignToVirtual(w,vw,1,1);
  9285.     for (i=1;i<=10;i++)
  9286.       VirtualWriteString(vw,"Hello World!!",i,1);
  9287.     GET_KEY();
  9288.     VirtualClear(vw);
  9289.   }
  9290.  
  9291.   If there is no error, VirtualClear() returns NO_ERROR.
  9292.  
  9293.   If there is an error, VirtualClear() returns the following values:
  9294.  
  9295.   BAD_V_WINDOW if the virtual window does not exist.
  9296.  
  9297.  
  9298.  
  9299.  
  9300.  
  9301.  
  9302.  
  9303.  Page 155                     The C Window Library                    Page 155
  9304.  
  9305.   VirtualClearAttr()
  9306.   ------------------
  9307.  
  9308.   The VirtualClearAttr() function works the same way as the VirtualClear()
  9309.   function except that an attribute is specified.  Here is the prototype:
  9310.  
  9311.               int VirtualClearAttr(VWPOINTER vw, int attr)
  9312.  
  9313.   The second argument is the video attribute to use.  If the virtual window is
  9314.   NOATTRIBUTE, this function only clears the text.
  9315.  
  9316.   Example:
  9317.  
  9318.   #include "window.h"
  9319.   #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  9320.   #define REVERSE CREATE_VIDEO_ATTRIBUTE(white,black)
  9321.   WPOINTER w;
  9322.   VWPOINTER vw;
  9323.  
  9324.   main()
  9325.   {
  9326.     int i;
  9327.     WindowInitializeSystem();
  9328.     WindowSaveInitial(0);
  9329.     w = WindowInitialize(BORDER,1,1,30,10,NORM,NORM,SINGLEBOX);
  9330.     vw = VirtualInitialize(ATTRIBUTE,30,80,NORM);
  9331.     WindowOpen(w);
  9332.     WindowDisplay(w,1,NOEFFECT);
  9333.     WindowAssignToVirtual(w,vw,1,1);
  9334.     for (i=1;i<=10;i++)
  9335.       VirtualWriteString(vw,"Hello World!!",i,1);
  9336.     GET_KEY();
  9337.     VirtualClearAttr(vw,REVERSE);
  9338.   }
  9339.  
  9340.   The return values for VirtualClearAttr() are the same as VirtualClear(),
  9341.   except for the following error:
  9342.  
  9343.     NO_ATTRIB if the virtual window is NOATTRIBUTE.
  9344.  
  9345.  
  9346.   VirtualClearRegion()
  9347.   -------------------
  9348.  
  9349.   The VirtualClearRegion() function clears a region of a virtual window.  To
  9350.   use the VirtualClearRegion() function, you must describe the rectangular
  9351.   region to clear.  Here is the prototype:
  9352.  
  9353.   int VirtualClearRegion(VWPOINTER vw, unsigned urow, unsigned ucol,
  9354.                          unsigned lrow, unsigned lcol)
  9355.  
  9356.   where (urow,ucol) describes the upper left of the rectangle and (lrow,lcol)
  9357.   is the lower right of the virtual window.
  9358.  
  9359.  Page 156                     The C Window Library                    Page 156
  9360.  
  9361.   Example:
  9362.  
  9363.   #include "window.h"
  9364.   #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  9365.   WPOINTER w;
  9366.   VWPOINTER vw;
  9367.  
  9368.   main()
  9369.   {
  9370.     int i;
  9371.     WindowInitializeSystem();
  9372.     WindowSaveInitial(0);
  9373.     w = WindowInitialize(BORDER,1,1,30,10,NORM,NORM,SINGLEBOX);
  9374.     vw = VirtualInitialize(NOATTRIBUTE,30,80,NORM);
  9375.     WindowOpen(w);
  9376.     WindowDisplay(w,1,NOEFFECT);
  9377.     WindowAssignToVirtual(w,vw,1,1);
  9378.     for (i=1;i<=10;i++)
  9379.       VirtualWriteString(vw,"Hello World!!",i,1);
  9380.     GET_KEY();
  9381.     VirtualClearRegion(vw,4,4,8,15);
  9382.   }
  9383.  
  9384.  
  9385.   The VirtualClearRegion() call will clear the region described by the
  9386.   rectangular coordinates (4,4) and (8,15).
  9387.  
  9388.   If there is no error, VirtualClearRegion() returns NO_ERROR.
  9389.  
  9390.   If there is an error, the VirtualClearRegion() function will return the
  9391.   following values:
  9392.  
  9393.   BAD_V_WINDOW if the VWPOINTER vw does not exist.
  9394.  
  9395.   V_WINDOW_BOUND if the rectangular region defined is out of bounds of the
  9396.                  virtual window.
  9397.  
  9398.  
  9399.  
  9400.  
  9401.  
  9402.   VirtualClearRegionAttr()
  9403.   ------------------------
  9404.  
  9405.   The VirtualClearRegionAttr() function works the same as the
  9406.   VirtualClearRegion() function, except that a video attribute is specified.
  9407.   Here is the prototype:
  9408.  
  9409.   int VirtualClearRegionAttr(VWPOINTER vw, unsigned urow, unsigned ucol,
  9410.                              unsigned lrow, unsigned lcol, int attr)
  9411.  
  9412.   The attr argument is a video attribute to use to clear the region.  If the
  9413.   virtual window is NOATTRIBUTE, the attribute argument is ignored.
  9414.  
  9415.  Page 157                     The C Window Library                    Page 157
  9416.  
  9417.   Example:
  9418.  
  9419.   #include "window.h"
  9420.   #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  9421.   #define REVERSE CREATE_VIDEO_ATTRIBUTE(white,black)
  9422.   WPOINTER w;
  9423.   VWPOINTER vw;
  9424.  
  9425.   main()
  9426.   {
  9427.     int i;
  9428.     WindowInitializeSystem();
  9429.     WindowSaveInitial(0);
  9430.     w = WindowInitialize(BORDER,1,1,30,10,NORM,NORM,SINGLEBOX);
  9431.     vw = VirtualInitialize(ATTRIBUTE,30,80,NORM);
  9432.     WindowOpen(w);
  9433.     WindowDisplay(w,1,NOEFFECT);
  9434.     WindowAssignToVirtual(w,vw,1,1);
  9435.     for (i=1;i<=10;i++)
  9436.       VirtualWriteString(vw,"Hello World!!",i,1);
  9437.     GET_KEY();
  9438.     VirtualClearRegionAttr(vw,4,4,8,15,REVERSE);
  9439.   }
  9440.  
  9441.  
  9442.   The VirtualClearRegionAttr() call will clear the region described by the
  9443.   rectangular coordinates (4,4) and (8,15) using the video attribute defined
  9444.   by the constant REVERSE.
  9445.  
  9446.   The VirtualClearRegionAttr() returns the same values as VirtualClearRegion()
  9447.   with an additional error condition:
  9448.  
  9449.     NO_ATTRIB if the virtual window is NOATTRIBUTE.
  9450.  
  9451.  
  9452.  
  9453.  
  9454.  
  9455.  
  9456.  
  9457.  
  9458.  
  9459.  
  9460.  
  9461.  
  9462.  
  9463.  
  9464.  
  9465.  
  9466.  
  9467.  
  9468.  
  9469.  
  9470.  
  9471.  Page 158                     The C Window Library                    Page 158
  9472.  
  9473.                               FREEZING VIEWPORTS
  9474.                               ------------------
  9475.  
  9476.  
  9477.   You can temporarily suspend or 'freeze' a viewport window from displaying
  9478.   updates to the virtual window.  This is good if there is data being written
  9479.   to the virtual window which takes a long time to generate.  The viewport can
  9480.   be frozen when the information is being written, and unfrozen when the
  9481.   writing of the data is terminated.
  9482.  
  9483.  
  9484.   WindowFreeze()
  9485.   --------------
  9486.  
  9487.   The WindowFreeze() function suspends or resumes displaying of virtual window
  9488.   updates on a viewport window.  Here is the prototype:
  9489.  
  9490.        int WindowFreeze(WPOINTER w, int option)
  9491.  
  9492.   The first argument is the viewport window, and the second argument is the
  9493.   option flag.  If this flag is 0, the window is unfrozen, i.e. the window will
  9494.   display virtual window updates.  If it is 1, the window will suspend virtual
  9495.   window updates from being displayed.
  9496.  
  9497.   Example:
  9498.  
  9499.   #include "window.h"
  9500.  
  9501.   #define NORM  CREATE_VIDEO_ATTRIBUTE(black,white)
  9502.  
  9503.   VWPOINTER vw;
  9504.   WPOINTER w;
  9505.  
  9506.   main()
  9507.   {
  9508.     int i;
  9509.     WindowInitializeSystem();
  9510.     WindowSaveInitial(0);
  9511.     w = WindowInitialize(BORDER,1,1,30,10,NORM,NORM,SINGLEBOX);
  9512.     vw = VirtualInitialize(NOATTRIBUTE,10,80,NORM);
  9513.     WindowOpen(w);
  9514.     WindowAssignToVirtual(w,vw,1,1);
  9515.     WindowDisplay(w,1,NOEFFECT);
  9516.     /* Freeze Viewport */
  9517.     WindowFreeze(w,1);
  9518.     for (i=1;i<=10;i++)
  9519.     {
  9520.       delay(1000);
  9521.       VirtualPrintf(vw,"Line %d\n",i);
  9522.     }
  9523.     /* Unfreeze window */
  9524.     WindowFreeze(w,0);
  9525.     GET_KEY();
  9526.  
  9527.  Page 159                     The C Window Library                    Page 159
  9528.  
  9529.     /* Now try with window always displaying data */
  9530.     VirtualClear(vw);
  9531.     for (i=1;i<=10;i++)
  9532.     {
  9533.       delay(1000);
  9534.       VirtualPrintf(vw,"Line %d\n",i);
  9535.     }
  9536.   }
  9537.  
  9538.  
  9539.  
  9540.   The above program first freezes the viewport w with the first call to
  9541.   WindowFreeze().  Then text is written slowly to the virtual window vw.  This
  9542.   text is not displayed until the window is unfrozen again with the second call
  9543.   to WindowFreeze().  Everything is reset and the writing of the text to the
  9544.   virtual window is done again, but this time the viewport is always displaying
  9545.   virtual window updates, even when the text is being written to the virtual
  9546.   window.
  9547.  
  9548.   The delay() function is discussed in the TIMED DELAYS section.
  9549.  
  9550.  
  9551.   If there is no error WindowFreeze() returns NO_ERROR.
  9552.  
  9553.   If there are errors, WindowFreeze() returns one of the following values:
  9554.  
  9555.   BAD_WINDOW if the viewport window does not exist.
  9556.  
  9557.   BAD_V_WINDOW if the virtual window that the viewport is displaying does not
  9558.   exist.
  9559.  
  9560.  
  9561.  
  9562.  
  9563.  
  9564.  
  9565.  
  9566.  
  9567.  
  9568.  
  9569.  
  9570.  
  9571.  
  9572.  
  9573.  
  9574.  
  9575.  
  9576.  
  9577.  
  9578.  
  9579.  
  9580.  
  9581.  
  9582.  
  9583.  Page 160                     The C Window Library                    Page 160
  9584.  
  9585.                          DISPOSING OF VIRTUAL WINDOWS
  9586.                          ----------------------------
  9587.  
  9588.  
  9589.   The last step is to dispose of the virtual window.  The function to do this
  9590.   is the VirtualFree() function.
  9591.  
  9592.  
  9593.   VirtualFree()
  9594.   -------------
  9595.  
  9596.   The VirtualFree() function frees all the memory allocated to the virtual
  9597.   window and destroys the virtual window pointer.  Here is the prototype:
  9598.  
  9599.        int VirtualFree(VWPOINTER vw, int hideflag, int effect)
  9600.  
  9601.   The first argument is the virtual window.  The second argument is a flag that
  9602.   determines whether any viewports displaying the virtual window should be
  9603.   hidden.  If this argument is 1, all viewports displaying the virtual window
  9604.   is hidden.  If the argument is 0, all viewports are cleared, but not hidden.
  9605.   The third argument is the special effect to use when hiding the viewports.
  9606.   This argument is ignored if hideflag is 0.  For a list of special effects,
  9607.   refer to the DISPLAYING WINDOWS section.
  9608.  
  9609.   Once VirtualFree() is called you must not use the VWPOINTER again unless you
  9610.   assign it to another virtual window, or create a new virtual window.
  9611.  
  9612.   Example:
  9613.  
  9614.    #include "window.h"
  9615.  
  9616.    #define NORM  CREATE_VIDEO_ATTRIBUTE(black,white)
  9617.    VWPOINTER vw;          /* virtual window pointer */
  9618.    WPOINTER w1, w2;
  9619.    main()
  9620.    {
  9621.      WindowInitializeSystem();
  9622.      WindowSaveInitial(0);
  9623.      vw = VirtualInitialize(NOATTRIBUTE,30,80,0);
  9624.      w1 = WindowInitialize(BORDER,1, 1,20,12,NORM,NORM,SINGLEBOX);
  9625.      w2 = WindowInitialize(BORDER,13,1,20,10,NORM,NORM,DOUBLEBOX);
  9626.      WindowOpen(w1);
  9627.      WindowOpen(w2);
  9628.      WindowDisplay(w1,1,NOEFFECT);
  9629.      WindowDisplay(w2,2,NOEFFECT);
  9630.      VirtualWriteString(vw,"This is a string",1,1);/* Write string to
  9631.                                                        virtual window */
  9632.      WindowAssignToVirtual(w1,vw,1,1); /* Assign viewport to virtual window */
  9633.      WindowAssignToVirtual(w2,vw,1,1); /* Assign viewport to virtual window */
  9634.      GET_KEY();
  9635.      VirtualFree(vw,1,NOEFFECT);  /* Destroy virtual window and hide
  9636.                                      w1,w2 */
  9637.    }
  9638.  
  9639.  Page 161                     The C Window Library                    Page 161
  9640.  
  9641.    If there are no errors, VirtualFree() returns NO_ERROR.
  9642.  
  9643.    If there are errors, VirtualFree() returns the following value:
  9644.  
  9645.    BAD_V_WINDOW if the virtual window does not exist.
  9646.  
  9647.  
  9648.  
  9649.  
  9650.  
  9651.  
  9652.  
  9653.  
  9654.  
  9655.  
  9656.  
  9657.  
  9658.  
  9659.  
  9660.  
  9661.  
  9662.  
  9663.  
  9664.  
  9665.  
  9666.  
  9667.  
  9668.  
  9669.  
  9670.  
  9671.  
  9672.  
  9673.  
  9674.  
  9675.  
  9676.  
  9677.  
  9678.  
  9679.  
  9680.  
  9681.  
  9682.  
  9683.  
  9684.  
  9685.  
  9686.  
  9687.  
  9688.  
  9689.  
  9690.  
  9691.  
  9692.  
  9693.  
  9694.  
  9695.  Page 162                     The C Window Library                    Page 162
  9696.  
  9697.                           INTRODUCTION TO MENU SYSTEM
  9698.                           ---------------------------
  9699.  
  9700.   Menu systems are important entities in any program.  The C Window Library has
  9701.   functions that create popup, pull-down, and bar menus.  The popup menus are
  9702.   scrollable menus with a limit of 65,535 selections.  The bar menus can have
  9703.   any number of entries.  As of this version, the bar menus are not scrollable,
  9704.   although there will be an implementation of scrolling bar menus in a future
  9705.   version.  The pull-down menus are a combination of popup and bar menus.
  9706.   You can change entries, hide entries, use hotkeys to invoke a menu entry,
  9707.   and many more things.
  9708.  
  9709.  
  9710.   Menu Manager
  9711.   ------------
  9712.  
  9713.   The menu manager is the code in The C Window Library that handles moving the
  9714.   highlight bar in the menu, calling the menu functions when they are selected,
  9715.   keeps tracks of available entries, and other functions that keep track of the
  9716.   menu when selections are made.
  9717.  
  9718.  
  9719.  
  9720.   Necessary "include" files
  9721.   -------------------------
  9722.  
  9723.   To use the menu system in your program, you must include the "menu.h" file
  9724.   supplied.  This file automatically includes the "window.h" file, therefore
  9725.   you do not have to include "window.h" when you use "menu.h".
  9726.  
  9727.  
  9728.  
  9729.  
  9730.  
  9731.  
  9732.  
  9733.  
  9734.  
  9735.  
  9736.  
  9737.  
  9738.  
  9739.  
  9740.  
  9741.  
  9742.  
  9743.  
  9744.  
  9745.  
  9746.  
  9747.  
  9748.  
  9749.  
  9750.  
  9751.  
  9752.  Page 163                     The C Window Library                    Page 163
  9753.  
  9754.                                POP-UP MENUS
  9755.                                ------------
  9756.  
  9757.  
  9758.   Description
  9759.   -----------
  9760.  
  9761.   A popup menu is a vertical menu with a list of entries that are selected by
  9762.   placing a highlight bar on the entry and pressing return, or by invoking the
  9763.   function by using a hotkey.  Pop-up menus can be scrollable, in other words,
  9764.   if there are more entries than can be displayed in the window, the menu will
  9765.   scroll through the rest of the selections.  You can have up to 65,535
  9766.   selections in the popup menu.
  9767.  
  9768.   Here is a partial list of the various options you can have with popup menus:
  9769.  
  9770.      * Highlight bar wrapping - wrap highlight bar to first or last option
  9771.                                 when there are no more selections.
  9772.  
  9773.      * Static Menus - menu remains on the screen when entry is selected.
  9774.  
  9775.      * Perpetual Menus - menu remain on the screen regardless of whether the
  9776.        PopupSelectMenu() function (explained later) is called or not.
  9777.  
  9778.      * Hidden (Unavailable) entries - You can make an entry in the popup menu
  9779.                                       unavailable or available at any time.
  9780.  
  9781.      * Color scheme of the menu - You can customize the color of the highlight
  9782.                                   bar, the hotkey letters, hidden entries,
  9783.                                   etc.
  9784.  
  9785.      * Change entry names   - You can safely change the names displayed in
  9786.                                the menu at any time.
  9787.  
  9788.      * Use a mouse to select menu entries.
  9789.  
  9790.  
  9791.  
  9792.  
  9793.   Windows and Virtual Windows
  9794.   ---------------------------
  9795.  
  9796.   Pop-up menus use virtual windows to write menu selections, and use normal
  9797.   windows to display the selections.  This method of using virtual windows
  9798.   enables the menu manager to scroll through the menu selections if the window
  9799.   is not tall enough to display all of the selections.
  9800.  
  9801.  
  9802.  
  9803.  
  9804.  
  9805.  
  9806.  
  9807.  Page 164                     The C Window Library                    Page 164
  9808.  
  9809.                              CREATING POP-UP MENUS
  9810.                              ---------------------
  9811.  
  9812.  
  9813.   The POPUP_MENU_ENTRY structure
  9814.   ------------------------------
  9815.  
  9816.   The two most important parts of the popup menu are the POPUP_MENU_ENTRY
  9817.   structure and the POPUP_MENU_PTR structure.  The POPUP_MENU_ENTRY structure
  9818.   is the first step in creating a popup menu and is discussed here.
  9819.  
  9820.   Each entry in the popup menu has its own POPUP_MENU_ENTRY structure
  9821.   associated with it.  The layout of this structure is as follows:
  9822.  
  9823.  
  9824.  
  9825.   char     *entry_name    -- This is the string that is displayed in the
  9826.                               popup virtual window.
  9827.  
  9828.   unsigned  row            -- Row in the virtual window to display entry_name.
  9829.  
  9830.   char      hotkey_letter  -- This is a character in entry_name that is
  9831.                               highlighted from the rest of the characters in
  9832.                               entry_name.  This letter will automatically
  9833.                               invoke the menu function associated with
  9834.                               entry_name.
  9835.  
  9836.   unsigned  ext_hotkey     -- This is a secondary hotkey.  The difference
  9837.                               between hotkey_letter and ext_hotkey is that
  9838.                               ext_hotkey can handle keys that are not ASCII keys
  9839.                               (the F keys, Alt and Ctrl key combinations, etc.).
  9840.  
  9841.   int (*func)()            -- Pointer to function that is invoked when option
  9842.                               is selected.
  9843.  
  9844.   An array of POPUP_MENU_ENTRY's are needed to create all of the entries on the
  9845.   popup menu.  The order of the array elements determine the order of how they
  9846.   are placed in the virtual window.  A code sample to create an array of
  9847.   POPUP_MENU_ENTRY's would be as follows:
  9848.  
  9849.   #include "menu.h"
  9850.   int menu_func();
  9851.  
  9852.   POPUP_MENU_ENTRY menu_items[] = {
  9853.                                   " Load      F3", /* entry name */
  9854.                                     1,             /* row number */
  9855.                                    'L',            /* hotkey */
  9856.                                     F3,            /* secondary hotkey */
  9857.                                     menu_func,     /* function to call if
  9858.                                                       chosen */
  9859.  
  9860.  
  9861.  
  9862.  
  9863.  Page 165                     The C Window Library                    Page 165
  9864.  
  9865.                                  /* now do rest of the popup entries */
  9866.  
  9867.                                   " Pick  Alt-F3",2, 'P',ALTF3,menu_func,
  9868.                                   " New"         ,3, 'N',0,menu_func,
  9869.                                   " Save      F2",4, 'S',F2,menu_func,
  9870.                                   " Write to    ",5, 'W',0,menu_func,
  9871.                                   " Directory   ",6, 'D',0,menu_func,
  9872.                                   " Change Dir"  ,7, 'C',0,menu_func,
  9873.                                   " OS shell"    ,8, 'O',0,menu_func,
  9874.                                   " Quit  Alt-X"  ,9,'Q',ALTX,menu_func,
  9875.  
  9876.                                  /* Terminate with a CWL_NULL and 0 */
  9877.                                   CWL_NULL,0};
  9878.  
  9879.  
  9880.   The first include file, menu.h, is must be included in each source file that
  9881.   calls menu functions.
  9882.  
  9883.   As you can see, there is an array of POPUP_MENU_ENTRY's, namely menu_items.
  9884.   Each entry consists of an entry name, row number, hotkey letter, secondary
  9885.   hotkey, and a function to call when the entry is selected.  The list of
  9886.   POPUP_MENU_ENTRY's MUST be terminated by a CWL_NULL entry name, and a row
  9887.   number of 0. If this rule is violated, the menu manager will not know where
  9888.   the last entry is, and will cause chaos when the program is run.
  9889.  
  9890.   If you are an advanced C programmer, you will no doubt find other ways in
  9891.   creating the array of POPUP_MENU_ENTRY's.  Other methods would be by dynamic
  9892.   allocation, reading in the entries from a disk file, etc.  The above example
  9893.   illustrates the easiest way to create the POPUP_MENU_ENTRY's.
  9894.  
  9895.  
  9896.  
  9897.   Defining Hotkeys
  9898.   ----------------
  9899.  
  9900.   The hotkey_letter defined in the POPUP_MENU_ENTRY structure must match one of
  9901.   the letters in its corresponding entry_name.  For example, " Load     F3",
  9902.   has the hotkey_letter defined as 'L'.  Since 'L' matches the first letter in
  9903.   " Load     F3",  the first 'L' in " Load     F3" is highlighted.  If there is
  9904.   no match, or if the hotkey_letter is 0, there is no hotkey associated with
  9905.   this option.  When the menu is displayed, either the 'l' or 'L' will be
  9906.   accepted as a valid selection to the entry " Load     F3".   If there is a
  9907.   POPUP_MENU_ENTRY with the same hotkey letter as another POPUP_MENU_ENTRY, the
  9908.   POPUP_MENU_ENTRY closest to the first entry is chosen.
  9909.  
  9910.   The ext_hotkey is used if the hotkey cannot be defined as a single character,
  9911.   or if you want another hotkey definition.  In the above example, the
  9912.   " Load     F3" entry_name has an ext_hotkey of F3 (defined in keycodes.h).
  9913.   If the F3 key is pressed, the function menu_func() is automatically invoked.
  9914.   If the ext_hotkey letter is 0, there is no ext_hotkey defined.  If there is a
  9915.   POPUP_MENU_ENTRY with the same ext_hotkey as another POPUP_MENU_ENTRY, the
  9916.   POPUP_MENU_ENTRY closest to the first entry is chosen.
  9917.  
  9918.  
  9919.  Page 166                     The C Window Library                    Page 166
  9920.  
  9921.   Assigning the function to perform
  9922.   ---------------------------------
  9923.  
  9924.   The func() member is the function that is performed when its corresponding
  9925.   entry_name is chosen.
  9926.  
  9927.  
  9928.   This is the first step in completing the total popup menu.  Once the array of
  9929.   POPUP_MENU_ENTRY's is created the next step is to define the colors for each
  9930.   element of the popup menu.
  9931.  
  9932.  
  9933.  
  9934.   Coloring Popup Menus
  9935.   --------------------
  9936.  
  9937.   An array of unsigned integers is used to define the color scheme of the popup
  9938.   menu.  Each element of this array stands for a certain area of the popup
  9939.   menu.  Here is a list of array positions and what they stand for.
  9940.  
  9941.   Position
  9942.   Constant
  9943.   --------
  9944.  
  9945.   ENTRYCOLOR    --  color of the text area of the viewport window.
  9946.   BORDERCOLOR    --  color of the border of the viewport window.
  9947.   HOTKEYCOLOR    --  color of the hotkey letter.
  9948.   HIGHLIGHTCOLOR --  color of the highlight bar.
  9949.   UNAVAILCOLOR   --  color of the unavailable entries.
  9950.  
  9951.   Position ENTRYCOLOR of the array defines the color of the text area of the
  9952.   viewport window.  This in turn defines the color of each entry_name of all
  9953.   of the POPUP_MENU_ENTRY's.
  9954.  
  9955.   Position BORDERCOLOR defines the color of the border of the viewport window.
  9956.   As was stated above, the menu is written to a virtual window, and a viewport
  9957.   is used to display the menu entries.  If the viewport window does not have a
  9958.   border, this attribute is ignored.
  9959.  
  9960.   Position HOTKEYCOLOR defines the color to use for the hotkey letter.  In the
  9961.   above example, the 'L', 'P', 'N', etc. of each respective entry_name is
  9962.   displayed using this color.
  9963.  
  9964.   Position HIGHLIGHTCOLOR defines the color used for the highlight bar.  This
  9965.   bar is moved up and down when the user is making a selection.
  9966.  
  9967.   Position UNAVAILCOLOR defines the color of the unavailable menu entries.
  9968.   Whenever a menu entry is unavailable, the entry_name string displayed takes
  9969.   on this color.
  9970.  
  9971.   Colors can be created by using the CREATE_VIDEO_ATTRIBUTE().  A code sample
  9972.   to create the colors is as follows:
  9973.  
  9974.  
  9975.  Page 167                     The C Window Library                    Page 167
  9976.  
  9977.   #include "menu.h"
  9978.   unsigned int menu_colors[5];
  9979.  
  9980.   main()
  9981.   {
  9982.     {... code ...}
  9983.     menu_colors[ENTRYCOLOR] = CREATE_VIDEO_ATTRIBUTE(black,white);
  9984.     menu_colors[BORDERCOLOR] = CREATE_VIDEO_ATTRIBUTE(black,white);
  9985.     menu_colors[HOTKEYCOLOR] = CREATE_VIDEO_ATTRIBUTE(blue,white);
  9986.     menu_colors[HIGHLIGHTCOLOR] = CREATE_VIDEO_ATTRIBUTE(black,cyan);
  9987.     menu_colors[UNAVAILCOLOR] = CREATE_VIDEO_ATTRIBUTE(white,black);
  9988.       /* rest of the program */
  9989.   }
  9990.  
  9991.   As in creating the POPUP_MENU_ENTRY's, if you are an advanced programmer,
  9992.   you will find other ways in assigning the colors.
  9993.  
  9994.  
  9995.  
  9996.   PopupCreateMenu() function
  9997.   --------------------------
  9998.  
  9999.   Now that you have created the POPUP_MENU_ENTRY's, and defined the color
  10000.   scheme, it is time to wrap all of these loose ends in one package.  The next
  10001.   step is to call the PopupCreateMenu() function.  This function combines all
  10002.   of the POPUP_MENU_ENTRY's, the colors you have defined, and other information
  10003.   into one entity called a POPUP_MENU_PTR.
  10004.  
  10005.   A POPUP_MENU_PTR is a pointer to a popup menu structure.  Just like a
  10006.   WPOINTER is a pointer to a window, a POPUP_MENU_PTR is used to reference the
  10007.   popup menu.
  10008.  
  10009.   A prototype of the call to PopupCreateMenu() is as follows:
  10010.  
  10011.   POPUP_MENU_PTR PopupCreateMenu(POPUP_MENU_ENTRY *p, unsigned *color, int row,
  10012.                                  int col, int height, unsigned options,
  10013.                                  WPOINTER (*wfunc)(), VWPOINTER (*vfunc)())
  10014.  
  10015.   To illustrate how to use this call, let's use the POPUP_MENU_ENTRY's and
  10016.   colors created in the previous examples:
  10017.  
  10018.   #include "menu.h"
  10019.   int menu_func();
  10020.   POPUP_MENU_ENTRY menu_items[] = {
  10021.                                   " Load      F3", /* entry name */
  10022.                                     1,             /* row number */
  10023.                                    'L',            /* hotkey */
  10024.                                     F3,            /* secondary hotkey */
  10025.                                     menu_func,     /* function to call if
  10026.                                                       chosen */
  10027.  
  10028.                                  /* now do rest of the popup entries */
  10029.  
  10030.  
  10031.  Page 168                     The C Window Library                    Page 168
  10032.  
  10033.                                   " Pick  Alt-F3",2, 'P',ALTF3,menu_func,
  10034.                                   " New"         ,3, 'N',0,menu_func,
  10035.                                   " Save      F2",4, 'S',F2,menu_func,
  10036.                                   " Write to    ",5, 'W',0,menu_func,
  10037.                                   " Directory   ",6, 'D',0,menu_func,
  10038.                                   " Change Dir"  ,7, 'C',0,menu_func,
  10039.                                   " OS shell"    ,8, 'O',0,menu_func,
  10040.                                   " Quit  Alt-X"  ,9,'Q',ALTX,menu_func,
  10041.  
  10042.  
  10043.                                  /* Terminate with a CWL_NULL and 0 */
  10044.  
  10045.                                   CWL_NULL,0};
  10046.  
  10047.   unsigned int menu_colors[5];
  10048.   POPUP_MENU_PTR p;
  10049.  
  10050.   main()
  10051.   {
  10052.     WindowInitializeSystem();          /* Initialize C Window Library */
  10053.  
  10054.    /* define colors */
  10055.  
  10056.     menu_colors[ENTRYCOLOR] = CREATE_VIDEO_ATTRIBUTE(black,white);
  10057.     menu_colors[BORDERCOLOR] = CREATE_VIDEO_ATTRIBUTE(black,white);
  10058.     menu_colors[HOTKEYCOLOR] = CREATE_VIDEO_ATTRIBUTE(blue,white);
  10059.     menu_colors[HIGHLIGHTCOLOR] = CREATE_VIDEO_ATTRIBUTE(black,cyan);
  10060.     menu_colors[UNAVAILCOLOR] = CREATE_VIDEO_ATTRIBUTE(white,black);
  10061.  
  10062.    /* create a POPUP_MENU_PTR */
  10063.  
  10064.    WindowSaveInitial(0);  /* Save initial screen    */
  10065.    p = PopupCreateMenu(menu_items,menu_colors, 10,10,9,NO_POPUP_OPTIONS,
  10066.                        WNULLFN,VWNULLFN);
  10067.   /* rest of the code */
  10068.   }
  10069.  
  10070.  
  10071.   In the example above there are two function calls that must be done before
  10072.   calling PopupCreateMenu().  The first mandatory function is
  10073.   WindowInitializeSystem().  The other function must be WindowSaveInitial()
  10074.   The WindowInitializeSystem() function must be called to initialize global
  10075.   variables used by the menu manager.  The WindowSaveInitial() function is a
  10076.   mandatory function because the PopupCreateMenu() function creates windows and
  10077.   virtual windows and assumes that the base screen has been saved.
  10078.  
  10079.   The example above declares the variable p to be a POPUP_MENU_PTR.  This
  10080.   POPUP_MENU_PTR is going to be used to reference the popup menu throughout the
  10081.   program.
  10082.  
  10083.   The first argument to PopupCreateMenu() is a pointer to the first
  10084.   POPUP_MENU_ENTRY.  In the above example,  menu_items is a pointer to the
  10085.   first POPUP_MENU_ENTRY.
  10086.  
  10087.  Page 169                     The C Window Library                    Page 169
  10088.  
  10089.   The second argument is a pointer to the array of colors.  In our example,
  10090.   menu_colors is our array of colors.
  10091.  
  10092.   The third and fourth arguments denote the row and column to place the upper
  10093.   left hand corner of the popup menu window.
  10094.  
  10095.   The fifth argument is the height of the popup menu window.  If the height of
  10096.   the window will not accommodate all of the menu items, the menu manager will
  10097.   scroll the window so that the entries that are obscured come into view.
  10098.  
  10099.   The sixth argument are various popup menu options that are assigned to the
  10100.   popup menus which are defined below.
  10101.  
  10102.  
  10103.   Popup Menu Options
  10104.   ------------------
  10105.  
  10106.   By default the menu manager assumes the following things:
  10107.  
  10108.     1)  The highlight bar does not wrap if the user wants to move the bar past
  10109.         the last entry, or before the first entry.
  10110.  
  10111.     2)  The menu will be hidden from the screen when a selection is made and
  10112.         will reappear when control is returned to the menu manager.
  10113.  
  10114.     3)  A function is automatically invoked when the hotkey is pressed instead
  10115.         of calling a user-defined function which will tell the menu manager
  10116.         whether the menu entry is to be executed.
  10117.  
  10118.     4)  The popup menu window is hidden when the menu manager returns control
  10119.         to the calling function.
  10120.  
  10121.     5)  The highlight bar will skip unavailable entries.
  10122.  
  10123.     6)  The menu manager does not recognize enhanced keys (F11, F12, etc.).
  10124.  
  10125.     7)  The mouse will not be used to move the highlight bar.
  10126.  
  10127.     8)  Scroll characters will not be displayed on the popup window.  The
  10128.         scroll characters allow the user to scroll through the options with a
  10129.         mouse.
  10130.  
  10131.  
  10132.   The last two options are only available if you have a Microsoft compatible
  10133.   mouse, and the mouse is activated.
  10134.  
  10135.   If the constant NO_POPUP_OPTIONS is used, the assumptions above are used.  If
  10136.   you want to override the above defaults, use the following options:
  10137.  
  10138.  
  10139.  
  10140.  
  10141.  
  10142.  
  10143.  Page 170                     The C Window Library                    Page 170
  10144.  
  10145.      Option Name              Definition
  10146.      -----------              ----------
  10147.       POPUPWRAP             Highlight bar wrapping.
  10148.       POPUPSTATIC           Do not hide menu when selection is made.
  10149.       POPUPCONFIRM          Confirmation when selection is made via hotkey.
  10150.       POPUPDISPLAY          Display menu even after exit.
  10151.       POPUPOVERRIDE         Accept Unavailable entries.
  10152.       POPUPENHANCEDKEY      Recognize enhanced keys.
  10153.       POPUPMOUSE            Use the mouse to select entries.
  10154.       POPUPMOUSESCROLL      Use the mouse to scroll through entries by placing
  10155.                             mouse on hotspots.
  10156.  
  10157.   As was stated before, the last two options, POPUPMOUSE and POPUPSCROLLCHARS,
  10158.   can only be used if you have a mouse installed, and the mouse is activated.
  10159.   More information on these two options is given in the USING A MOUSE section.
  10160.  
  10161.   By turning the above options "on" the following is assumed:
  10162.  
  10163.     1)  POPUPWRAP will wrap the highlight bar if the user wants to move the bar
  10164.         past the last entry or before the first entry.
  10165.  
  10166.     2)  POPUPSTATIC will not hide the menu when a selection is made.
  10167.  
  10168.     3)  POPUPCONFIRM will call a user-defined function before invoking the
  10169.         hotkey that was selected.  This function will then return an integer
  10170.         back to the menu manager informing whether the function selected should
  10171.         be invoked, or the request should be rejected.  There is more
  10172.         information on this option in the SETTING OPTIONS IN POPUP MENUS
  10173.         section below.
  10174.  
  10175.     4)  POPUPDISPLAY will not hide the popup window when the menu manager
  10176.         returns control to the calling function.
  10177.  
  10178.     5)  POPUPOVERRIDE will make the menu manager accept unavailable entries.
  10179.  
  10180.     6)  POPUPENHANCEDKEY will inform the menu manager that enhanced keys will
  10181.         be recognized.
  10182.  
  10183.     7)  POPUPMOUSE allows the use of a mouse to make selections.
  10184.  
  10185.     8)  POPUPMOUSESCROLL allows the user to scroll through the options using a
  10186.         mouse.
  10187.  
  10188.   You can also set multiple options by using a bitwise OR (|).  For example:
  10189.  
  10190.     p = PopupCreateMenu(arg1,arg2,arg3,arg4,arg5,
  10191.                         POPUPWRAP | POPUPSTATIC | POPUPCONFIRM,arg7,arg8)
  10192.  
  10193.   will set options POPUPWRAP, POPUPSTATIC, and POPUPCONFIRM defined above.
  10194.  
  10195.  
  10196.  
  10197.  
  10198.  
  10199.  Page 171                     The C Window Library                    Page 171
  10200.  
  10201.   The last two arguments to PopupCreateMenu() are defined in the next sections.
  10202.  
  10203.  
  10204.   Default Popup Window and Creating Your own Windows
  10205.   --------------------------------------------------
  10206.  
  10207.   The sixth argument to the PopupCreateMenu() function is a pointer to a
  10208.   function that will open a popup menu window.  If this is a NULL function
  10209.   pointer (WNULLFN), the menu manager will create a window.  For most
  10210.   applications, the window that the menu manager will create is adequate.  The
  10211.   menu manager uses these defaults when making the popup window:
  10212.  
  10213.      - A bordered window with the border consisting of single lines (SINGLEBOX).
  10214.      - The width of the window is determined by the longest entry_name in the
  10215.        POPUP_MENU_ENTRY's.
  10216.  
  10217.   If you want to create your own popup menu window, your function must return a
  10218.   WPOINTER.  Inside your function you must create and open a window using
  10219.   WindowInitialize() and WindowOpen().  For most applications, you do not have
  10220.   to display the window, instead the menu manager can do the displaying and
  10221.   hiding of the windows.
  10222.  
  10223.   Here is an example of creating your own custom window function:
  10224.  
  10225.   #include "menu.h"
  10226.   /* Other includes and menu stuff */
  10227.   WPOINTER my_open();
  10228.   POPUP_MENU_PTR p;
  10229.   main()
  10230.   {
  10231.      /*   Other code */
  10232.      p = PopupCreateMenu(menu_items,menu_colors,10,10,9,my_open,WNULLFN);
  10233.      /* More code */
  10234.   }
  10235.  
  10236.   WPOINTER my_open()
  10237.   {
  10238.     WPOINTER w;
  10239.     w = WindowInitialize(NOBORDER,1,1,20,10,BLACKONWHITE,BLACKONWHITE,"");
  10240.     WindowOpen(w);
  10241.     return w;       /* May be WIN_NULL_PTR, but must return to
  10242.                        PopupCreateMenu() */
  10243.   }
  10244.  
  10245.   The example above lets the menu manager know that the window creation
  10246.   function is a user written function called my_open.  The row, column and
  10247.   height arguments (arguments 3, 4 and 5) of PopupCreateMenu() will be ignored
  10248.   when using a custom window function.  The row, column and height parameters
  10249.   used to create the window in the call to WindowInitialize() in my_window()
  10250.   will take precedence over the arguments 3, 4, and 5 used in PopupCreateMenu().
  10251.  
  10252.  
  10253.  
  10254.  
  10255.  Page 172                     The C Window Library                    Page 172
  10256.  
  10257.   Default Virtual Window and
  10258.   Creating Your own Virtual Windows
  10259.   ---------------------------------
  10260.  
  10261.   The last argument to PopupCreateMenu() is a pointer to a function that will
  10262.   return a VWPOINTER.  This function creates the virtual window used to write
  10263.   the menu entries.  If this is a NULL function pointer (VWNULLFN), the menu
  10264.   manager will create the virtual window.  If you do specify a function,  your
  10265.   virtual window must have enough rows to hold all of the POPUP_MENU_ENTRY's,
  10266.   and be wide enough to hold the length of the longest entry_name.
  10267.  
  10268.   When the menu manager creates the virtual window, the following defaults are
  10269.   assumed:
  10270.  
  10271.    a) the virtual window has its own video attributes.
  10272.    b) Must be large enough to hold all the POPUP_MENU_ENTRY's.
  10273.  
  10274.   Your custom function should create a virtual window which follows both rules.
  10275.  
  10276.   You must also make sure that the virtual window was created and opened
  10277.   successfully.  If the virtual window cannot be created because of a lack of
  10278.   memory, you must return the NULL virtual window pointer instead.  From there,
  10279.   PopupCreateMenu() will do any cleaning up and will return with a null
  10280.   POPUP_MENU_PTR.
  10281.  
  10282.   My last advice when calling the PopupCreateMenu() function is that your best
  10283.   bet is to let the menu manager create the windows and virtual windows.  You
  10284.   can always resize, change border types, etc. later on.  Since virtual
  10285.   window's are not visible anyway, it makes sense to let the menu manager
  10286.   determine how the virtual window should be created.  The last two arguments
  10287.   to the PopupCreateMenu() function are for those programmers who need full
  10288.   control of window, and virtual window management.
  10289.  
  10290.  
  10291.  
  10292.   Accessing Popup Windows and Virtual Windows
  10293.   -------------------------------------------
  10294.  
  10295.   After calling the PopupCreateMenu() function, you can access the popup window
  10296.   by using the POPUP_WINDOW() macro.  In the above example, p is the
  10297.   POPUP_MENU_PTR and the value of POPUP_WINDOW(p) is a pointer to the popup
  10298.   menu's window.  If you want to change borders move, slide, or anything you
  10299.   can do with normal windows, you must access the popup window in this way.
  10300.  
  10301.   For example, if you want to change the border of the popup window you would
  10302.   do the following:
  10303.  
  10304.  
  10305.       p = PopupCreateMenu(...  /* other arguments */ )
  10306.       WindowDrawBorder(POPUP_WINDOW(p),DOUBLEBOX);  /* change border to a
  10307.                                                        double lined box */
  10308.   The example calls WindowDrawBorder() to change the border of the popup
  10309.   window.
  10310.  
  10311.  Page 173                     The C Window Library                    Page 173
  10312.  
  10313.   If you want to write information to the virtual window created by the
  10314.   PopupCreateMenu() function, you can access the virtual window by using the
  10315.   POPUP_VIRTUAL_WINDOW() macro.  By accessing the popup-menu's virtual window,
  10316.   you can read and write to and from the virtual window.  This is very useful
  10317.   if you want to draw horizontal lines in your menu.  An example would be as
  10318.   follows:
  10319.  
  10320.       char *h = "----------------------";
  10321.  
  10322.       /* ...Some code... */
  10323.  
  10324.       p = PopupCreateMenu(menu_items,menu_colors,10,10,9,WNULLFN,VWNULLFN);
  10325.       VirtualWriteString(POPUP_VIRTUAL_WINDOW(p),h,8,1);
  10326.  
  10327.  
  10328.   Warnings
  10329.   --------
  10330.  
  10331.   Do not call WindowFree(), WindowClose() or VirtualFree() on the window or the
  10332.   virtual window of the popup menu.  The menu manager will call these functions
  10333.   when PopupMenuFree() is called.  If you close the popup window, or the
  10334.   virtual window on an active menu, the menu manager will assume that these
  10335.   windows still exist.  Doing so will almost guarantee your application will
  10336.   bomb out.
  10337.  
  10338.  
  10339.   Return Values for PopupCreateMenu()
  10340.   -----------------------------------
  10341.   If there are no errors, PopupCreateMenu() returns a valid POPUP_MENU_PTR
  10342.   pointer.  If there is an error when PopupCreateMenu() is called, a null
  10343.   POPUP_MENU_PTR is returned.  Here are the possible reasons why an error has
  10344.   occurred:
  10345.  
  10346.     1) There is not enough memory to allocate for the POPUP_MENU_PTR or its
  10347.        internal data structures.
  10348.  
  10349.     2) There is not enough memory to allocate for the popup window.
  10350.  
  10351.     3) There is not enough memory to allocate for the virtual window.
  10352.  
  10353.     4) The popup window's size was invalid.
  10354.  
  10355.  
  10356.   Problems 1,2, and 3 all are caused by a lack of heap memory.  Problem 4 stems
  10357.   from having invalid parameters in the PopupCreateMenu().  The arguments that
  10358.   are suspect are the third, fourth, and fifth arguments.  To remedy this
  10359.   problem, adjust these arguments such that the window can fit on the screen.
  10360.  
  10361.   For all of the above conditions, you can get the actual error code by
  10362.   checking the value of the global integer window_error_code.  If
  10363.   window_error_code is equal to NO_HEAP_MEM, then condition 1, 2, or 3 has
  10364.   occurred.  If it is equal to BAD_WINDOW_SIZE, then condition 4 has occurred.
  10365.  
  10366.  Page 174                     The C Window Library                    Page 174
  10367.  
  10368.   If you have a custom window or virtual window opening function, it is your
  10369.   responsibility to check the error conditions that may occur, and return
  10370.   correct values or null pointers if you cannot rectify the error in your
  10371.   custom routine.
  10372.  
  10373.  
  10374.   Here is an example:
  10375.  
  10376.   Example:
  10377.        int status;
  10378.        POPUP_MENU_PTR p;
  10379.        p = PopupCreateMenu(...);
  10380.        if (p == (POPUP_MENU_PTR)0)  {   /* check for null pointer */
  10381.          if (window_error_code == NO_HEAP_MEM)
  10382.             /* ... Condition 1,2, or 3 occurred */
  10383.          else
  10384.            /* Condition 4 occurred */
  10385.        }
  10386.  
  10387.  
  10388.  
  10389.  
  10390.  
  10391.  
  10392.  
  10393.  
  10394.  
  10395.  
  10396.  
  10397.  
  10398.  
  10399.  
  10400.  
  10401.  
  10402.  
  10403.  
  10404.  
  10405.  
  10406.  
  10407.  
  10408.  
  10409.  
  10410.  
  10411.  
  10412.  
  10413.  
  10414.  
  10415.  
  10416.  
  10417.  
  10418.  
  10419.  
  10420.  
  10421.  
  10422.  Page 175                     The C Window Library                    Page 175
  10423.  
  10424.                           SELECTING FROM POPUP MENUS
  10425.                           --------------------------
  10426.  
  10427.   We have now created the popup menu.  Now how do we get the menu manager to
  10428.   act on our popup window?  The answer is the PopupSelectMenu() function.
  10429.  
  10430.  
  10431.   PopupSelectMenu() function
  10432.   --------------------------
  10433.  
  10434.   The PopupSelectMenu() function displays the popup window, and allows the
  10435.   user to move the highlight bar until he/she has placed the bar on the desired
  10436.   option, or the user presses a hotkey to invoke one of the entries.
  10437.  
  10438.   Before the call to the PopupSelectMenu(), nothing has been displayed.  This
  10439.   means that you can resize the popup window, change borders, write strings to
  10440.   the popup menus virtual window, etc. while everything is hidden away from
  10441.   view.  The only time when the popup menu is displayed is when the call to
  10442.   PopupSelectMenu() is made (or unless you have displayed the popup window
  10443.   yourself using WindowDisplay()).
  10444.  
  10445.   A prototype of the call to PopupSelectMenu() is as follows:
  10446.  
  10447.        int PopupSelectMenu(POPUP_MENU_PTR p, int rank, unsigned start)
  10448.  
  10449.   The first argument is the POPUP_MENU_PTR.  The second argument is the rank of
  10450.   the popup window.  As with other windows, the rank determines how the window
  10451.   will be situated on the screen with respect to the other windows.  The last
  10452.   argument is the number of the menu entry of where the highlight bar should be
  10453.   situated.  Usually this is 1, but this will give you the option to start on
  10454.   any one of the menu entries.  If the start value is out of bounds (say you
  10455.   have specified start to be 5 while there are only 4 menu entries) the menu
  10456.   manager will default to the first menu option.
  10457.  
  10458.   Now let's put everything together:
  10459.  
  10460.  
  10461.   #include "menu.h"
  10462.   int menu_func();
  10463.  
  10464.   POPUP_MENU_ENTRY menu_items[] = {
  10465.                                   " Load      F3", /* entry name */
  10466.                                     1,             /* row number */
  10467.                                    'L',            /* hotkey */
  10468.                                     F3,            /* secondary hotkey */
  10469.                                     menu_func,     /* function to call
  10470.                                                       if chosen */
  10471.  
  10472.                                  /* now do rest of the popup entries */
  10473.  
  10474.  
  10475.  
  10476.  
  10477.  
  10478.  Page 176                     The C Window Library                    Page 176
  10479.  
  10480.                                   " Pick  Alt-F3",2, 'P',ALTF3,menu_func,
  10481.                                   " New"         ,3, 'N',0,menu_func,
  10482.                                   " Save      F2",4, 'S',F2,menu_func,
  10483.                                   " Write to    ",5, 'W',0,menu_func,
  10484.                                   " Directory   ",6, 'D',0,menu_func,
  10485.                                   " Change Dir"  ,7, 'C',0,menu_func,
  10486.                                   " OS shell"    ,8, 'O',0,menu_func,
  10487.                                   " Quit  Alt-X"  ,9,'Q',ALTX,menu_func,
  10488.  
  10489.                                  /* Terminate with a CWL_NULL and 0 */
  10490.  
  10491.                                   CWL_NULL,0};
  10492.   unsigned int menu_colors[5];
  10493.   POPUP_MENU_PTR p;
  10494.  
  10495.   main()
  10496.   {
  10497.     WindowInitializeSystem();
  10498.     WindowSaveInitial(0);  /* Remember to save the initial screen */
  10499.    /* define colors */
  10500.     menu_colors[ENTRYCOLOR] = CREATE_VIDEO_ATTRIBUTE(white,black);
  10501.     menu_colors[BORDERCOLOR] = CREATE_VIDEO_ATTRIBUTE(white,black);
  10502.     menu_colors[HOTKEYCOLOR] = CREATE_VIDEO_ATTRIBUTE(white,blue);
  10503.     menu_colors[HIGHLIGHTCOLOR] = CREATE_VIDEO_ATTRIBUTE(cyan,black);
  10504.     menu_colors[UNAVAILCOLOR] = CREATE_VIDEO_ATTRIBUTE(white,black);
  10505.  
  10506.    /* create a POPUP_MENU_PTR */
  10507.    p = PopupCreateMenu(menu_items,menu_colors, 1,1,6,POPUPSTATIC,WNULLFN,VWNULLFN);
  10508.    PopupSelectMenu(p,  /* POPUP_MENU_PTR */
  10509.                      1,  /* rank of popup window */
  10510.                      1   /* menu entry to start on */
  10511.                     );
  10512.   }
  10513.  
  10514.  
  10515.   int menu_func(POPUP_MENU_PTR p, unsigned which)
  10516.   {
  10517.     WPOINTER w;
  10518.     w = WindowInitialize(BORDER,15,15,40,4,CREATE_VIDEO_ATTRIBUTE(black,white),
  10519.                          CREATE_VIDEO_ATTRIBUTE(black,white), SINGLEBOX);
  10520.     WindowOpen(w);
  10521.     WindowClear(w);
  10522.     WindowPrintf(w,"You have selected %s",POPUP_ENTRY_STRING(p,which));
  10523.     WindowWriteCenterString(w,"Press a key to continue",3);
  10524.     WindowDisplay(w,1,NOEFFECT);
  10525.     GET_KEY();
  10526.     WindowFree(w,NOEFFECT);
  10527.     if (which == 9)
  10528.       return POPUP_EXIT;
  10529.     else
  10530.     return POPUP_CONTINUE;
  10531.   }
  10532.  
  10533.  
  10534.  Page 177                     The C Window Library                    Page 177
  10535.  
  10536.   The above example has a call to PopupSelectMenu().  The arguments passed are
  10537.   p as the POPUP_MENU_PTR, a window rank of 1, and a starting position of 1.
  10538.   The POPUP_ENTRY_STRING() macro in the menu_func() function returns the entry
  10539.   string for the particualr menu entry.  The first argument is the
  10540.   POPUP_MENU_PTR and the second argument is the entry number.
  10541.  
  10542.  
  10543.  
  10544.  
  10545.   Values passed to menu function
  10546.   ------------------------------
  10547.  
  10548.   When a selection is made, the menu manager will call the function defined
  10549.   for the selection, and pass two arguments to this function.  The first
  10550.   argument passed is the POPUP_MENU_PTR of the current popup menu and the
  10551.   second argument is the number of the entry selected.  Entry numbers are
  10552.   numbered from 1 to the highest entry in the menu.  For example, if the " Load
  10553.   F3" entry is selected, the menu manager will pass the POPUP_MENU_PTR p, and a
  10554.   1 to func().  If " Pick ALT-F3" is chosen, the menu manager passes a 2 as the
  10555.   second argument to func() etc.
  10556.  
  10557.  
  10558.  
  10559.  
  10560.   Values returned to menu manager
  10561.   -------------------------------
  10562.  
  10563.   The user function must return an integer back to the menu manager.  If the
  10564.   value returned to the menu manager is POPUP_EXIT, the menu manager will exit
  10565.   from the current menu and will return control back to the function that
  10566.   called it.  If the return value is POPUP_CONTINUE, the menu continues to
  10567.   process selections.
  10568.  
  10569.   The menu_func() function defined above creates a window, displays the entry
  10570.   you have chosen, and returns a value back to the menu manager.  If the value
  10571.   is POPUP_EXIT, the menu manager returns control back to the function that
  10572.   called it.  In this case, main() called PopupSelectMenu().  A return value of
  10573.   POPUP_CONTINUE will cause the menu manager to let the user make another
  10574.   selection.
  10575.  
  10576.   The menu_func() function is a simple implementation.  However your function
  10577.   can do much more sophisticated things, including opening other popup menus.
  10578.   If another popup menu is called while in another popup menu, the new popup
  10579.   menu gets its own menu manager and will not interfere with the original menu
  10580.   manager.  This is good if a menu function will call another menu function.
  10581.  
  10582.  
  10583.  
  10584.  
  10585.  
  10586.  
  10587.  
  10588.  
  10589.  
  10590.  Page 178                     The C Window Library                    Page 178
  10591.  
  10592.   Return Values for PopupSelectMenu()
  10593.   -----------------------------------
  10594.  
  10595.   If no errors occurred when PopupSelectMenu() is called the menu manager
  10596.   returns NO_ERROR when the menu is closed.  There are three possibilities for
  10597.   errors when calling PopupSelectMenu().  Here are the three possible errors:
  10598.  
  10599.   1) The popup menus window does not exist.
  10600.  
  10601.   2) The popup menus window is not opened.
  10602.  
  10603.   3) The virtual window does not exist.
  10604.  
  10605.   The first error occurred because the PopupCreateMenu() function or your
  10606.   custom window function could not initialize the popup menu window, you
  10607.   inadvertently called WindowFree() on the popup menu's window, or you are
  10608.   overwriting data with a stray pointer.
  10609.  
  10610.   Error 2 can occur if the you inadvertently called WindowClose() on the popup
  10611.   menu's window, or you are overwriting data with a stray pointer.
  10612.  
  10613.   Error 3 can occur if PopupCreateMenu() or your custom virtual window
  10614.   function could not create the virtual window, or a stray pointer is
  10615.   overwriting data.
  10616.  
  10617.   For all of the above conditions, you can get the actual error code by
  10618.   checking the value of the global integer window_error_code or by checking
  10619.   the return value of PopupSelectMenu().  Here is a list of return values and
  10620.   their corresponding reasons:
  10621.  
  10622.     Return Value               Condition
  10623.     ------------               ---------
  10624.     BAD_WINDOW                    1
  10625.     WINDOW_NOT_OPEN               2
  10626.     BAD_V_WINDOW                  3
  10627.  
  10628.  
  10629.  
  10630.  
  10631.  
  10632.  
  10633.  
  10634.  
  10635.  
  10636.  
  10637.  
  10638.  
  10639.  
  10640.  
  10641.  
  10642.  
  10643.  
  10644.  
  10645.  
  10646.  Page 179                     The C Window Library                    Page 179
  10647.  
  10648.                         SETTING OPTIONS IN POPUP MENUS
  10649.                         ------------------------------
  10650.  
  10651.   In addition to setting options using the PopupCreateMenu() function, you can
  10652.   turn on and off options at any time using the PopupSetOptions() function.
  10653.  
  10654.  
  10655.   The PopupSetOptions() function
  10656.   ------------------------------
  10657.  
  10658.   The PopupSetOptions() function turns either one or more of the above
  10659.   options on or off.  The prototype to the call is as follows:
  10660.  
  10661.          int PopupSetOptions(POPUP_MENU_PTR p, int option, int switch)
  10662.  
  10663.   The first argument is the POPUP_MENU_PTR.  The second argument are the
  10664.   options that you wish to change.  The constants that describe the options are
  10665.   exactly the same as the ones described in PopupCreateMenu().  The third
  10666.   argument is whether you want to switch the options on or off.
  10667.  
  10668.     Here are some sample calls to PopupSetOptions():
  10669.  
  10670.       a) PopupSetOptions(p,POPUPWRAP,1)
  10671.       b) PopupSetOptions(p,POPUPSTATIC,1)
  10672.       c) PopupSetOptions(p,POPUPCONFIRM,1)
  10673.       d) PopupSetOptions(p,POPUPSTATIC,0)
  10674.       e) PopupSetOptions(p,POPUPDISPLAY,1)
  10675.       f) PopupSetOptions(p,POPUPOVERRIDE,1)
  10676.       g) PopupSetOptions(p,POPUPENHANCEDKEY,1)
  10677.  
  10678.   The third argument is 1 for "on", 0 for "off".
  10679.  
  10680.   Example a) sets the highlight bar so that it will wrap.
  10681.  
  10682.   Example b) informs the menu manager that the menu will not be hidden when a
  10683.   selection is made.
  10684.  
  10685.   Example c) will tell the menu manager to call a user defined function that
  10686.   will inform the menu manager whether to invoke the selection in the menu.
  10687.  
  10688.   Example d) Informs the menu manager to hide the menu window when a menu
  10689.   function is invoked.
  10690.  
  10691.   Example e) Informs the menu manager not to hide the menu when control is
  10692.   returned to the function that called PopupSelectMenu().
  10693.  
  10694.   Example f) Informs the menu manager to process unavailable entries.  This is
  10695.   useful if you want to set up your own error routine if the user selects an
  10696.   unavailable entry.
  10697.  
  10698.   Example g) imforms the menu manager to distinguish between normal keys and
  10699.   enhanced keys.
  10700.  
  10701.  
  10702.  Page 180                     The C Window Library                    Page 180
  10703.  
  10704.   Setting Multiple Options
  10705.   ------------------------
  10706.   You can also set multiple options with a single call by using a bitwise OR
  10707.   (|).  For example:
  10708.  
  10709.     PopupSetOptions(p,POPUPWRAP | POPUPSTATIC | POPUPCONFIRM,1)
  10710.  
  10711.   will set options POPUPWRAP, POPUPSTATIC, and POPUPCONFIRM defined above.
  10712.  
  10713.  
  10714.  
  10715.   Setting the PopupSetConfirmFunction()
  10716.   -------------------------------------
  10717.  
  10718.   When using the POPUPCONFIRM option, you must also use the
  10719.   PopupSetConfirmFunction() function to point the menu to the confirmation
  10720.   function that will be called when a hotkey is pressed.  Here is a prototype
  10721.   of the PopupSetConfirmFunction():
  10722.  
  10723.            PopupSetConfirmFunction(POPUP_MENU_PTR p, int (*func)())
  10724.  
  10725.   where p is the desired popup menu to assign the confirmation function to,
  10726.   and func is a pointer to a function that will return a value back to the menu
  10727.   manager that will inform it to either invoke the option, or ignore the
  10728.   option.
  10729.  
  10730.   When the confirmation function is called, the menu manager passes three
  10731.   arguments to func.  The prototype for your user defined function should be as
  10732.   follows:
  10733.  
  10734.         int my_confirm_func(POPUP_MENU_PTR p, unsigned key, unsigned sel)
  10735.  
  10736.   where p is the POPUP_MENU_PTR that is currently being processed, key is the
  10737.   hotkey that was pressed, and sel is the selection where the highlight bar is
  10738.   now positioned.  The highlight bar is always positioned on the hotkey
  10739.   selection even if it may not be invoked.  This user defined function must
  10740.   return a value back to the menu manager.  The valid values that can be
  10741.   returned are POPUP_CONTINUE and POPUP_DO_CHOICE.  If POPUP_CONTINUE is
  10742.   returned, the menu selection is not invoked, if POPUP_DO_CHOICE is selected,
  10743.   the menu entry is invoked.  Here is an example:
  10744.  
  10745.      #include "menu.h"
  10746.  
  10747.      int my_confirm_func();
  10748.      POPUP_MENU_PTR p;
  10749.  
  10750.      /* ... */
  10751.      main()
  10752.      {
  10753.        PopupSetOptions(p,POPUPCONFIRM,1);
  10754.        PopupSetConfirmFunction(p,my_confirm_func);
  10755.        /* ... */
  10756.      }
  10757.  
  10758.  Page 181                     The C Window Library                    Page 181
  10759.  
  10760.      my_confirm_func(POPUP_MENU_PTR p, unsigned k, unsigned sel)
  10761.      {
  10762.        /* ... */
  10763.        if (k == 'C' || k == 'c' || k == ALTF)
  10764.          return POPUP_CONTINUE;
  10765.        else
  10766.          return POPUP_DO_CHOICE;
  10767.      }
  10768.  
  10769.   The above function invokes the menu selection if the hotkey that was pressed
  10770.   is not a 'C', 'c', or ALT-F.
  10771.  
  10772.   The confirmation function can do anything, including setting options in the
  10773.   popup menu, displaying other windows etc.
  10774.  
  10775.  
  10776.  
  10777.   Return Values for PopupSetOptions() function
  10778.   --------------------------------------------
  10779.  
  10780.   You can use the PopupSetOptions() function at any time, including before
  10781.   calling the PopupSelectMenu() function.  If the option is not a valid option,
  10782.   the function returns NO_ERROR, but does not change anything.  If the switch
  10783.   is not 0 or 1, a 1 is assumed.
  10784.  
  10785.   If there is an error, the error conditions and reasons are the same as the
  10786.   PopupSelectMenu() function defined above.
  10787.  
  10788.  
  10789.  
  10790.  
  10791.  
  10792.  
  10793.  
  10794.  
  10795.  
  10796.  
  10797.  
  10798.  
  10799.  
  10800.  
  10801.  
  10802.  
  10803.  
  10804.  
  10805.  
  10806.  
  10807.  
  10808.  
  10809.  
  10810.  
  10811.  
  10812.  
  10813.  
  10814.  Page 182                     The C Window Library                    Page 182
  10815.  
  10816.                  MAKING MENU ENTRIES AVAILABLE AND UNAVAILABLE
  10817.                  ---------------------------------------------
  10818.  
  10819.   There may be cases when a menu entry should be made unavailable.  The entry
  10820.   shows up in the menu, but it is a different color than the other entries, and
  10821.   the highlight bar will just skip over this unavailable entry.
  10822.  
  10823.  
  10824.  
  10825.   PopupMakeEntryAvailable() and
  10826.   PopupMakeEntryUnavailable() functions
  10827.   -------------------------------------
  10828.  
  10829.   With The C Window Library, you can make entries available and unavailable at
  10830.   any time.  The PopupMakeEntryAvailable() and the PopupMakeEntryUnavailable()
  10831.   functions perform these tasks.
  10832.  
  10833.   A prototype of the call to both of these functions is as follows:
  10834.  
  10835.         int PopupMakeEntryAvailable(POPUP_MENU_PTR p, unsigned entry)
  10836.         int PopupMakeEntryUnavailable(POPUP_MENU_PTR p, unsigned entry)
  10837.  
  10838.   The first argument is the POPUP_MENU_PTR.  The second argument is the number
  10839.   of the entry that you wish to change.  Entry numbers range from 1 to the
  10840.   highest entry in the menu.
  10841.  
  10842.  
  10843.  
  10844.   POPUPOVERRIDE option
  10845.   --------------------
  10846.  
  10847.   If the POPUPOVERRIDE option is set (see above), the menu manager will still
  10848.   process unavailable entries.  You must turn off POPUPOVERRIDE by using the
  10849.   PopupSetOptions() function if you do not want to process unavailable entries.
  10850.  
  10851.  
  10852.  
  10853.   Return Values for PopupMakeEntryAvaialble() and
  10854.   PopupMakeEntryUnavailable() functions
  10855.   -----------------------------------------------
  10856.  
  10857.   If there is no error, both of these functions return NO_ERROR.
  10858.   If there is an error, the following possibilities can occur:
  10859.  
  10860.   1) The error can be one of the errors defined above for the PopupSelectMenu()
  10861.  
  10862.   2) The menu entry is invalid.
  10863.  
  10864.   Refer to the PopupSelectMenu() return values and reasons for failure defined
  10865.   above for error condition 1).  If the error is 2), check to see if the entry
  10866.   number supplied is valid.  The entry number cannot be < 1 or greater than the
  10867.   number of selections in the popup menu.
  10868.  
  10869.  
  10870.  Page 183                     The C Window Library                    Page 183
  10871.  
  10872.   If error 2) has occurred, the PopupMakeEntryAvailable() and the
  10873.   PopupMakeEntryUnavailable() return MENU_ENTRY_INVALID.
  10874.  
  10875.  
  10876.  
  10877.  
  10878.  
  10879.  
  10880.  
  10881.  
  10882.  
  10883.  
  10884.  
  10885.  
  10886.  
  10887.  
  10888.  
  10889.  
  10890.  
  10891.  
  10892.  
  10893.  
  10894.  
  10895.  
  10896.  
  10897.  
  10898.  
  10899.  
  10900.  
  10901.  
  10902.  
  10903.  
  10904.  
  10905.  
  10906.  
  10907.  
  10908.  
  10909.  
  10910.  
  10911.  
  10912.  
  10913.  
  10914.  
  10915.  
  10916.  
  10917.  
  10918.  
  10919.  
  10920.  
  10921.  
  10922.  
  10923.  
  10924.  
  10925.  
  10926.  Page 184                     The C Window Library                    Page 184
  10927.  
  10928.                      CHANGING THE MENU ENTRY STRINGS
  10929.                      -------------------------------
  10930.  
  10931.   There may be times when you want to change a POPUP_MENU_ENTRY entry_name
  10932.   string.  For instance, you may have a menu entry with the following
  10933.   entry_name:
  10934.  
  10935.           "Default File Name     ABC.DAT"
  10936.  
  10937.  
  10938.   If the user selects this choice, the file name should change to another file
  10939.   name the user wants.  From there the menu should reflect the new choice the
  10940.   user has made.  Let's say the user has changed the default file name to
  10941.   DEF.DAT.  The menu then should say:
  10942.  
  10943.           "Default File Name     DEF.DAT"
  10944.  
  10945.  
  10946.  
  10947.   PopupChangeEntryString() function
  10948.   ---------------------------------
  10949.  
  10950.   How do you change the entry string?  One way is to fool around with the
  10951.   POPUP_MENU_PTR's structure members, and change the string yourself.  This is
  10952.   not recommended for the novice to average C programmer, since it is not a good
  10953.   idea to change the structure members directly without a full understanding of
  10954.   the structure.
  10955.  
  10956.   A safer way is to call the PopupChangeEntryString() function.  A prototype of
  10957.   this function is as follows:
  10958.  
  10959.      PopupChangeEntryString(POPUP_MENU_PTR p, unsigned entry, char *newstring)
  10960.  
  10961.   The first argument is the POPUP_MENU_PTR.  The second argument is the number
  10962.   of the entry that you wish to change.  Entry numbers range from 1 to the
  10963.   highest entry in the menu.  The third argument is a pointer to the new
  10964.   character string.  The newstring cannot be longer than the current
  10965.   POPUP_MENU_ENTRY entry_name string.
  10966.  
  10967.  
  10968.  
  10969.  
  10970.   Return Values for PopupChangeEntryString() function
  10971.   ---------------------------------------------------
  10972.  
  10973.   If there is no error, NO_ERROR is returned.
  10974.  
  10975.   If there is an error, the error conditions and reasons are the same as the
  10976.   PopupMakeEntryAvailable() function defined above.
  10977.  
  10978.  
  10979.  
  10980.  
  10981.  
  10982.  Page 185                     The C Window Library                    Page 185
  10983.  
  10984.                            REDEFINING MENU KEYS
  10985.                            --------------------
  10986.  
  10987.  
  10988.   Setting Global Key Definitions and
  10989.   the popup_key_definition Array
  10990.   ----------------------------------
  10991.  
  10992.   You can redefine the keys used to control moving the highlight bar, accepting
  10993.   the menu choice, and exiting from the menu.  Here is a list of the default key
  10994.   mapping:
  10995.  
  10996.        Function                      Key             Constant
  10997.        --------                      ---              ------
  10998.      Move highlight bar up         Up Arrow        POPUP_UPKEY
  10999.      Move highlight bar down       Down Arrow      POPUP_DOWNKEY
  11000.      Accept Menu Choice            Enter           POPUP_ACCEPTKEY
  11001.      Escape Pop-up menu            Escape          POPUP_QUITKEY
  11002.      Move To First Menu Item       Home            POPUP_HOMEKEY
  11003.      Move to Last Menu Item        End             POPUP_ENDKEY
  11004.      Scroll entries up by one
  11005.      page                          PgUp            POPUP_PAGEUPKEY
  11006.      Scroll entries down by one
  11007.      page                          PgDn            POPUP_PAGEDOWNKEY
  11008.     *Move To Next Popup Menu       Not Assigned    POPUP_RIGHTKEY
  11009.     *Move to Previous Popup Menu   Not Assigned    POPUP_LEFTKEY
  11010.     *Escape Pulldown Menu          Not Assigned    POPUP_PULLDOWN_QUITKEY
  11011.  
  11012.   The global array popup_key_definition contains the values of the default
  11013.   popup menu key definitions.  The names under the Constant heading are the
  11014.   offsets in the popup_key_definition array of where the key value for the
  11015.   function is defined.  For instance, the value for the "Move highlight bar up"
  11016.   function is located at popup_key_definition[POPUP_UPKEY].  You can change the
  11017.   values in popup_key_definition at any time, but make sure that a definition
  11018.   for "Escape Pop-up menu" always exists, and that there are no duplicate
  11019.   definitions (i.e.  the "Move highlight bar up" key definition is the same as
  11020.   the "Move highlight bar down" key definition).  When defining new key values,
  11021.   you should use the values defined in the keycodes.h header file for non-ascii
  11022.   keys.
  11023.  
  11024.   * The POPUP_RIGHTKEY, POPUP_LEFTKEY, and the POPUP_PULLDOWN_QUITKEY
  11025.     definitions only apply to popup menus that are incorporated in a pulldown
  11026.     menu.  See the section on pulldown menus for more information.
  11027.  
  11028.  
  11029.  
  11030.  
  11031.   Setting Local Key Definitions
  11032.   -----------------------------
  11033.  
  11034.   Another way of redefining menu keys is to load your own array of key
  11035.   definitions with your desired values, and then calling the PopupAssignKeys()
  11036.   function.  With this method, each menu can have different key definitions.
  11037.  
  11038.  Page 186                     The C Window Library                    Page 186
  11039.  
  11040.   PopupAssignKeys() function
  11041.   --------------------------
  11042.  
  11043.   Here is a prototype of the PopupAssignKeys() function:
  11044.  
  11045.               int PopupAssignKeys(POPUP_MENU_PTR p, unsigned *keys)
  11046.  
  11047.   where p is the POPUP_MENU_PTR, and keys is an array of key definitions.  Here
  11048.   is a small code example:
  11049.  
  11050.  
  11051.   #include "menu.h"
  11052.  
  11053.   unsigned mykeys[NUMPOPUPKEYS] = {CTRLU,CTRLD,RETURN,ESC,HOME,END,0,0,0,0};
  11054.   POPUP_MENU_PTR p;
  11055.  
  11056.   /* Other stuff...*/
  11057.  
  11058.   main()
  11059.   {
  11060.     /* Assume p is initialized */
  11061.  
  11062.     PopupAssignKeys(p,mykeys); /* Assigns my key definitions to popup menu p */
  11063.   }
  11064.  
  11065.   The constant NUMPOPUPKEYS should be used to make sure that your array of key
  11066.   definitions is large enough to hold all the definitions.   The above example
  11067.   uses the constants defined in keycodes.h to assign to the array mykeys.  Each
  11068.   position in the mykeys array uses the default key mapping explained above.
  11069.   In other words, mykeys[POPUP_UPKEY] is CTRLU, etc.
  11070.  
  11071.  
  11072.  
  11073.   Return Values for PopupAssignKeys() function
  11074.   --------------------------------------------
  11075.  
  11076.   If there is no error, then NO_ERROR is returned.
  11077.  
  11078.   If there is an error, the error conditions and reasons are the same as the
  11079.   PopupSelectMenu() function defined above.
  11080.  
  11081.  
  11082.  
  11083.  
  11084.  
  11085.  
  11086.  
  11087.  
  11088.  
  11089.  
  11090.  
  11091.  
  11092.  
  11093.  
  11094.  
  11095.  
  11096.  Page 187                     The C Window Library                    Page 187
  11097.  
  11098.                            PROCESSING UNDEFINED KEYS
  11099.                            -------------------------
  11100.  
  11101.   If you are an advanced programmer and/or have experience in using other
  11102.   window/menu libraries, you may be wondering "how do I define a function that
  11103.   supplies context-sensitive help for each POPUP_MENU_ENTRY?  There is no
  11104.   structure member in POPUP_MENU_ENTRY that supplies this".  With The C Window
  11105.   Library, any key that is not recognized by the menu manager (i.e. the key
  11106.   struck does not invoke a menu option, move the highlight bar up or down, or
  11107.   ends processing of the menu) can be processed by calling a user written
  11108.   function.   The WindowGet...() family of functions allowed us to define a
  11109.   function that will be called if a key that has no current definition is
  11110.   pressed.  For popup menus, we can do the same thing.
  11111.  
  11112.  
  11113.   The popup_undef_key function pointer
  11114.   ------------------------------------
  11115.  
  11116.   The global function pointer, popup_undef_key, can point to a user written
  11117.   function that will be called when the menu manager encounters a key that is
  11118.   not defined.  The declaration for popup_undef_key is as follows:
  11119.  
  11120.     unsigned int (*popup_undef_key)(POPUP_MENU_PTR p, unsigned int sel,
  11121.                                     unsigned int *choice)
  11122.  
  11123.   The user written function takes three arguments.  The first argument is a
  11124.   pointer to the popup menu that the menu manager is currently processing. The
  11125.   second argument is an integer that contains the value of the key that was
  11126.   pressed.  The third argument is a pointer to an integer that will contain the
  11127.   number of the menu choice to execute.  Initially, choice points to an integer
  11128.   that contains the current menu choice that the menu highlight bar is situated.
  11129.   For instance, if the highlight bar is on the first menu choice when an
  11130.   undefined key is pressed, *choice will be equal to 1.  If popup_undef_key is
  11131.   equal to a Null Function pointer (NULLFN), no user defined function is called.
  11132.   By default, popup_undef_key is assigned to NULLFN.
  11133.  
  11134.  
  11135.   Values returned to menu manager
  11136.   -------------------------------
  11137.  
  11138.   If popup_undef_key is assigned to a function, the function must return an
  11139.   integer back to the menu manager.  This integer value will tell the menu
  11140.   manager how to proceed.  Here is a list of the valid return values that the
  11141.   user written function can return:
  11142.  
  11143.  
  11144.  
  11145.  
  11146.  
  11147.  
  11148.  
  11149.  
  11150.  
  11151.  
  11152.  Page 188                     The C Window Library                    Page 188
  11153.  
  11154.     Return                         Action to
  11155.     Value                            Take
  11156.     ------                         ---------
  11157.  
  11158.    POPUP_CONTINUE          No Action. Continue processing the popup menu.
  11159.    POPUP_MOVE_UP           Move the highlight bar up.
  11160.    POPUP_MOVE_DOWN         Move the highlight bar down.
  11161.    POPUP_DO_CHOICE         Accept and invoke menu entry assigned to *choice.
  11162.    POPUP_MOVE_CONTINUE     Move the highlight bar to menu entry assigned to
  11163.                               *choice and continue processing menu.
  11164.    POPUP_ESCAPE            Escape the popup menu.
  11165.    POPUP_MOVE_HOME         Move highlight to first available menu entry.
  11166.    POPUP_MOVE_END          Move highlight to last available menu entry.
  11167.    POPUP_MOVE_PAGEUP       Scroll the entries in the popup window up by one
  11168.                            "page" (a page is the current height of the popup
  11169.                            window).
  11170.    POPUP_MOVE_PAGEDOWN     Scroll the entries in the popup window down by one
  11171.                            "page" (a page is the current height of the popup
  11172.                            window).
  11173.   *POPUP_MOVE_LEFT         Move to next popup menu.
  11174.   *POPUP_MOVE_RIGHT        Move to previous popup menu.
  11175.   *POPUP_PULLDOWN_QUIT     Escape pulldown menu
  11176.  
  11177.   A return value of POPUP_CONTINUE is a "do nothing" command to the menu
  11178.   manager.
  11179.  
  11180.   If POPUP_DO_CHOICE is returned to the menu manager, the integer assigned to
  11181.   the parameter *choice is used as the menu entry to invoke.  The highlight
  11182.   bar will automatically be moved to the menu choice specified, and the menu
  11183.   function will be called.  If POPUP_MOVE_CONTINUE is returned to the menu
  11184.   manager, the highlight bar will be moved to the entry specified by the
  11185.   value of *choice, but no function is called.
  11186.  
  11187.   Return values of POPUP_DO_CHOICE and POPUP_MOVE_CONTINUE only work when the
  11188.   menu entry specified by *choice is an available entry or the POPUPVERRIDE
  11189.   option is on , otherwise the menu manager just continues processing the
  11190.   popup menu.
  11191.  
  11192.  
  11193.   * The POPUP_MOVE_RIGHT, POPUP_MOVE_LEFT, and POPUP_PULLDOWN_QUIT only apply
  11194.     to popup menus that are incorporated in a pulldown menu system.  See the
  11195.     section on pulldown menus for more information.
  11196.  
  11197.   Here is an example of using a user defined function for the undefined keys:
  11198.  
  11199.   #include "menu.h"
  11200.  
  11201.   /*  Other includes */
  11202.  
  11203.   int user_func();
  11204.  
  11205.  
  11206.  
  11207.  
  11208.  Page 189                     The C Window Library                    Page 189
  11209.  
  11210.   main()
  11211.  
  11212.   {
  11213.     popup_undef_key = user_func;
  11214.  
  11215.     /* Other code */
  11216.   }
  11217.  
  11218.   unsigned int user_func(POPUP_MENU_PTR p, unsigned sel, unsigned *choice)
  11219.   {
  11220.     switch(sel)
  11221.  
  11222.     {
  11223.       case F1:
  11224.         help(*choice);         /* call help function */
  11225.         return POPUP_CONTINUE; /* return "do nothing" command to menu manager */
  11226.       case F2:
  11227.         *choice = 6;  /* let menu manager know to do choice 6 on the menu */
  11228.         return POPUP_DO_CHOICE;     /* Also let menu manager know we are
  11229.                                      returning the "do the function assigned to
  11230.                                      *choice" command */
  11231.       default:
  11232.         return POPUP_CONTINUE;
  11233.         /* let menu manager know not to do anything */
  11234.     }
  11235.   }
  11236.  
  11237.   int help(int choice)
  11238.   {  /* help function */
  11239.     switch (choice)
  11240.     {
  11241.       case 1:
  11242.         /* do context-sensitive help for entry 1 */
  11243.       break;
  11244.       case 2:
  11245.         /* do context-sensitive help for entry 2 */
  11246.       break;
  11247.        /* do more entries */
  11248.        /* ... */
  11249.     }
  11250.   }
  11251.  
  11252.   In the above example, if the user hits F1, a help function is called.  If you
  11253.   wanted to know how to incorporate a help function in the popup menus, here is
  11254.   the way to do it.
  11255.  
  11256.   If the user hits F2, the integer pointed to by choice is assigned a 6, and
  11257.   user_func() returns POPUP_DO_CHOICE to the menu manager.  This tells the
  11258.   menu manager to invoke the function assigned to menu entry 6.
  11259.  
  11260.  
  11261.  
  11262.  
  11263.  
  11264.  Page 190                     The C Window Library                    Page 190
  11265.  
  11266.                               PRE-INPUT FUNCTION
  11267.                               ------------------
  11268.  
  11269.   With The C Window Library, you can define a function that will be performed
  11270.   just before the menu manager waits for the user to enter a keystroke.  This
  11271.   function can perform just about anything.
  11272.  
  11273.  
  11274.   Setting the global_popup_prefunc function pointer
  11275.   -------------------------------------------------
  11276.  
  11277.   The global_popup_prefunc function pointer points to this user written
  11278.   function.  Here is the prototype:
  11279.  
  11280.       int (*global_popup_prefunc)(POPUP_MENU_PTR p, unsigned *sel)
  11281.  
  11282.   The arguments that will be passed to your function are the following:
  11283.  
  11284.   a)  The POPUP_MENU_PTR of the popup menu that called your function, and
  11285.  
  11286.   b)  A pointer to the number of the selection that the highlight bar is
  11287.       currently on.
  11288.  
  11289.   The selection number ranges from 1 to the highest entry number of the menu.
  11290.  
  11291.   The pre-input function MUST return a value back to the menu manager.  The
  11292.   return values that can be returned are the same as the popup_undef_key
  11293.   function described above.  If you are using a version of The C Window Library
  11294.   prior to version 1.5, you must declare your pre-input function as returning
  11295.   an int, and you must return a value back to the menu manager.  Versions prior
  11296.   to 1.5 declared the pre-input function as void.
  11297.  
  11298.   The POPUP_DO_CHOICE and POPUP_MOVE_CONTINUE return values will move the
  11299.   highlight bar to the entry number that is assigned to the *sel argument when
  11300.   the pre-input function has returned.
  11301.  
  11302.   By default, global_popup_prefunc points to a NULLFN, and therefore will not be
  11303.   performed.  However, you can implement pre-input functions depending on the
  11304.   current selection.  For instance, you can write a function that displays
  11305.   extra information for each entry like so:
  11306.  
  11307.   #include "menu.h"
  11308.  
  11309.   char *mess[] = {
  11310.                    " This option saves and loads files",
  11311.                    " This brings you in edit mode",
  11312.                    " This compiles and/or links the current program",
  11313.  
  11314.                    /* ... More stuff */
  11315.                    };
  11316.  
  11317.  
  11318.  
  11319.  
  11320.  Page 191                     The C Window Library                    Page 191
  11321.  
  11322.   WPOINTER message_window;
  11323.  
  11324.   int disp_info();
  11325.  
  11326.   main()
  11327.   {
  11328.     /* ... */
  11329.  
  11330.     global_popup_prefunc = disp_info;
  11331.  
  11332.     /* ... */
  11333.   }
  11334.  
  11335.   int disp_info(POPUP_MENU_PTR p, unsigned *sel)
  11336.   {
  11337.      /* Assume message_window already created and opened */
  11338.  
  11339.     WindowClear(message_window,CREATE_VIDEO_ATTRIBUTE(black,white));
  11340.     WindowWriteString(message_window,mess[*sel-1],1,1);
  11341.     return POPUP_CONTINUE;
  11342.   }
  11343.  
  11344.  
  11345.   For simplicity, the menu definitions are left out of the preceding code
  11346.   sample.  The disp_info displays the appropriate description in the window
  11347.   message_window.  POPUP_CONTINUE is returned to the menu manager.  This
  11348.   informs the menu manager to continue looking for a keystroke.
  11349.  
  11350.  
  11351.  
  11352.  
  11353.  
  11354.  
  11355.  
  11356.  
  11357.  
  11358.  
  11359.  
  11360.  
  11361.  
  11362.  
  11363.  
  11364.  
  11365.  
  11366.  
  11367.  
  11368.  
  11369.  
  11370.  
  11371.  
  11372.  
  11373.  
  11374.  
  11375.  
  11376.  Page 192                     The C Window Library                    Page 192
  11377.  
  11378.                            DISPOSING OF POPUP MENUS
  11379.                            ------------------------
  11380.  
  11381.  
  11382.   PopupMenuFree()
  11383.   ---------------
  11384.  
  11385.   If the popup menu is no longer needed, the PopupMenuFree() function will
  11386.   dispose of the popup menu and return any memory allocated to the popup menu,
  11387.   window, and virtual window memory back to the heap.  The call to the function
  11388.   is very simple:
  11389.  
  11390.          PopupMenuFree(POPUP_MENU_PTR p)
  11391.  
  11392.   where p is the POPUP_MENU_PTR to dispose of.  Since this function destroys the
  11393.   POPUP_MENU_PTR p, p must not be used for any popup menu functions, unless p
  11394.   is pointing to a valid POPUP_MENU_PTR.
  11395.  
  11396.  
  11397.  
  11398.   Return Values for PopupMenuFree()
  11399.   ---------------------------------
  11400.  
  11401.   The return values and the reasons for failure are the same as
  11402.   PopupSelectMenu().
  11403.  
  11404.  
  11405.  
  11406.  
  11407.  
  11408.  
  11409.  
  11410.  
  11411.  
  11412.  
  11413.  
  11414.  
  11415.  
  11416.  
  11417.  
  11418.  
  11419.  
  11420.  
  11421.  
  11422.  
  11423.  
  11424.  
  11425.  
  11426.  
  11427.  
  11428.  
  11429.  
  11430.  
  11431.  
  11432.  Page 193                     The C Window Library                    Page 193
  11433.  
  11434.                                BAR MENUS
  11435.                                ---------
  11436.  
  11437.   Description
  11438.   -----------
  11439.  
  11440.  
  11441.   A bar menu is a horizontal menu with a list of entries that are selected by
  11442.   placing a highlight bar on the option and pressing return, or by invoking the
  11443.   function by using a hotkey.  Bar menus can span several lines. In other
  11444.   words, menu entries do not have to fit on a single line.
  11445.  
  11446.  
  11447.   Here is a partial list of the various options you can have with bar menus:
  11448.  
  11449.      * Highlight bar wrapping - wrap highlight bar to first or last option
  11450.                                 when there are no more selections.
  11451.  
  11452.      * Static Menus           - menu remains on the screen when entry is
  11453.                                 selected.
  11454.  
  11455.      * Perpetual Menus        - menu remain on the screen regardless of
  11456.                                 whether the BarSelectMenu() function
  11457.                                 (explained later) is called or not.
  11458.  
  11459.      * Hidden (Unavailable) entries - You can make an entry in the bar menu
  11460.                                       unavailable or available at any time.
  11461.  
  11462.      * Color scheme of the menu - You can customize the color of the highlight
  11463.                                   bar, the hotkey letters, hidden entries,
  11464.                                   etc.
  11465.  
  11466.      * Change entry names       - You can safely change the names displayed in
  11467.                                   the menu at any time.
  11468.  
  11469.      * Use a mouse to select menu entries.
  11470.  
  11471.  
  11472.  
  11473.  
  11474.   Windows and Virtual Windows
  11475.   ---------------------------
  11476.  
  11477.   Unlike popup menus, bar menus do not use virtual windows.  Only normal text
  11478.   windows are used.
  11479.  
  11480.  
  11481.  
  11482.  
  11483.  
  11484.  
  11485.  
  11486.  
  11487.  
  11488.  Page 194                     The C Window Library                    Page 194
  11489.  
  11490.                              CREATING BAR MENUS
  11491.                              ------------------
  11492.  
  11493.  
  11494.  
  11495.   The BAR_MENU_ENTRY structure
  11496.   ----------------------------
  11497.  
  11498.   The two most important parts of the bar menu are the BAR_MENU_ENTRY structure
  11499.   and the BAR_MENU_PTR structure.  The BAR_MENU_ENTRY structure is the first
  11500.   step in creating a bar menu and is discussed here.
  11501.  
  11502.   Each entry in the bar menu has its own BAR_MENU_ENTRY structure associated
  11503.   with it.  The layout of this structure is as follows:
  11504.  
  11505.  
  11506.   char     *entry_name     -- This is the string that is displayed in the
  11507.                               bar window.
  11508.  
  11509.   unsigned  row            -- Row in the window to display entry_name.
  11510.  
  11511.   char      hotkey_letter  -- This is a character in entry_name that is
  11512.                               highlighted from the rest of the characters in
  11513.                               entry_name.  This letter will automatically
  11514.                               invoke the menu function associated with
  11515.                               entry_name.
  11516.  
  11517.   unsigned  ext_hotkey     -- This is a secondary hotkey.  The difference
  11518.                               between hotkey_letter and ext_hotkey is that
  11519.                               ext_hotkey can handle keys that are not ASCII keys
  11520.                               (the F keys, Alt and Ctrl key combinations, etc.).
  11521.  
  11522.   int (*func)()            -- Pointer to function that is invoked when option
  11523.                               is selected.
  11524.  
  11525.  
  11526.   An array of BAR_MENU_ENTRY's are needed to create all of the entries on the
  11527.   bar menu.  The order of the array elements determine the order of how they
  11528.   are placed in the  window.  A code sample to create an array of
  11529.   BAR_MENU_ENTRY's would be as follows:
  11530.  
  11531.   #include "menu.h"
  11532.   int menu_func();
  11533.  
  11534.   BAR_MENU_ENTRY bar_items[] = {
  11535.                         "File",    /* option name */
  11536.                          1,        /* row in window to display option name */
  11537.                          4,        /* col. in window to display option */
  11538.                         'F',       /* hotkey letter */
  11539.                         ALTF,      /* secondary hotkey */
  11540.                         rt2,       /* function to do if chosen */ ,
  11541.  
  11542.  
  11543.  
  11544.  Page 195                     The C Window Library                    Page 195
  11545.  
  11546.                         /* Now define the rest of the BAR_MENU_ENTRY's */
  11547.                         "Edit",1,10,'E',0,menu_func,
  11548.                         "Run",1,17,'R',0,menu_func,
  11549.                         "Compile",1,23,'C',0,menu_func,
  11550.                         "Project",1,33,'P',0,menu_func,
  11551.                         "Options",1,43,'O',0,menu_func,
  11552.                         "Debug",1,53,'D',0,menu_func,
  11553.                         "Break/watch",1,61,'B',0,menu_func,
  11554.  
  11555.                         /* Now terminate with a CWL_NULL option_name */
  11556.                          CWL_NULL};
  11557.  
  11558.  
  11559.   The first include file, menu.h, is must be included in each source file that
  11560.   calls menu functions.
  11561.  
  11562.   As you can see, there is an array of BAR_MENU_ENTRY's, namely bar_items.
  11563.   Each entry consists of an entry name, row number, column number, hotkey
  11564.   letter, secondary hotkey, and a function to call when the entry is selected.
  11565.   The list of BAR_MENU_ENTRY's MUST be terminated by a CWL_NULL entry name.
  11566.  
  11567.   If you are an advanced C programmer, you will no doubt find other ways in
  11568.   creating the array of BAR_MENU_ENTRY's.  Other methods would be by dynamic
  11569.   allocation, reading in the entries from a disk file, etc.  The above example
  11570.   illustrates the easiest way to create the BAR_MENU_ENTRY's.
  11571.  
  11572.   If you are an advanced C programmer, you will no doubt find other ways in
  11573.   creating the array of BAR_MENU_ENTRY's.  Other methods would be by dynamic
  11574.   allocation, reading in the entries from a disk file, etc.  The above example
  11575.   illustrates the easiest way to create the BAR_MENU_ENTRY's.
  11576.  
  11577.  
  11578.  
  11579.   Defining Hotkeys
  11580.   ----------------
  11581.  
  11582.   The hotkey_letter defined in the BAR_MENU_ENTRY structure must match one of
  11583.   the letters in its corresponding entry_name.  For example, "File", has the
  11584.   hotkey_letter defined as 'F'.  Since 'F' matches the first letter in "File",
  11585.   the first 'F' in "File" is highlighted.  If there is no match, or if the
  11586.   hotkey_letter is 0, there is no hotkey associated with this entry.  When the
  11587.   menu is displayed, either the 'f' or 'F' will be accepted as a valid selection
  11588.   to the entry "File".   If there is a BAR_MENU_ENTRY with the same hotkey
  11589.   letter as another BAR_MENU_ENTRY, the BAR_MENU_ENTRY closest to the first
  11590.   entry is chosen.
  11591.  
  11592.   The ext_hotkey is used if the hotkey cannot be defined as a single character,
  11593.   or if you want another hotkey definition.  In the above example, the "File"
  11594.   entry_name has an ext_hotkey of ALTF3 (defined in keycodes.h).  If the ALT-F3
  11595.   key is pressed, the function rt2() is automatically invoked.  If the
  11596.   ext_hotkey letter is 0, there is no ext_hotkey defined.  If there is a
  11597.   BAR_MENU_ENTRY with the same ext_hotkey as another BAR_MENU_ENTRY, the
  11598.   BAR_MENU_ENTRY closest to the first entry is chosen.
  11599.  
  11600.  Page 196                     The C Window Library                    Page 196
  11601.  
  11602.   Assigning the function to perform
  11603.   ---------------------------------
  11604.  
  11605.   The func() member is the function that is performed when its corresponding
  11606.   entry_name is chosen.
  11607.  
  11608.  
  11609.   This is the first step in completing the total bar menu.  Once the array of
  11610.   BAR_MENU_ENTRY's is created the next step is to define the colors for each
  11611.   element of the bar menu.
  11612.  
  11613.  
  11614.  
  11615.   Coloring Bar Menus
  11616.   ------------------
  11617.  
  11618.   An array of unsigned integers is used to define the color scheme of the bar
  11619.   menu.  Each element of this array stands for a certain area of the bar
  11620.   menu.  Here is a list of array positions and what they stand for.
  11621.  
  11622.  
  11623.   Position
  11624.   Constant
  11625.   --------
  11626.  
  11627.   ENTRYCOLOR    --  color of the text area of the window.
  11628.   BORDERCOLOR    --  color of the border of the window.
  11629.   HOTKEYCOLOR    --  color of the hotkey letter.
  11630.   HIGHLIGHTCOLOR --  color of the highlight bar.
  11631.   UNAVAILCOLOR   --  color of the unavailable entries.
  11632.  
  11633.   Position ENTRYCOLOR of the array defines the color of the text area of the
  11634.   viewport window.  This in turn defines the color of each entry_name of all
  11635.   of the BAR_MENU_ENTRY's.
  11636.  
  11637.   Position BORDERCOLOR defines the color of the border of the window.  If
  11638.   the window does not have a border, this attribute is ignored.
  11639.  
  11640.   Position HOTKEYCOLOR defines the color to use for the hotkey letter.  In the
  11641.   above example, the 'L', 'P', 'N', etc. of each respective entry_name is
  11642.   displayed using this color.
  11643.  
  11644.   Position HIGHLIGHTCOLOR defines the color used for the highlight bar.  This
  11645.   bar is moved up and down when the user is making a selection.
  11646.  
  11647.   Position UNAVAILCOLOR defines the color of the unavailable menu entries.
  11648.   Whenever a menu entry is unavailable, the entry_name string displayed takes
  11649.   on this color.
  11650.  
  11651.   Colors can be created by using the CREATE_VIDEO_ATTRIBUTE() macro.   A code
  11652.   sample to create the colors is as follows:
  11653.  
  11654.  
  11655.  
  11656.  Page 197                     The C Window Library                    Page 197
  11657.  
  11658.   #include "menu.h"
  11659.   unsigned int menu_colors[5];
  11660.  
  11661.   main()
  11662.   {
  11663.     {... code ...}
  11664.     menu_colors[ENTRYCOLOR] = CREATE_VIDEO_ATTRIBUTE(black,white);
  11665.     menu_colors[BORDERCOLOR] = CREATE_VIDEO_ATTRIBUTE(black,white);
  11666.     menu_colors[HOTKEYCOLOR] = CREATE_VIDEO_ATTRIBUTE(blue,white);
  11667.     menu_colors[HIGHLIGHTCOLOR] = CREATE_VIDEO_ATTRIBUTE(black,cyan);
  11668.     menu_colors[UNAVAILCOLOR] = CREATE_VIDEO_ATTRIBUTE(white,black);
  11669.       /* rest of the program */
  11670.   }
  11671.  
  11672.  
  11673.   As in creating the BAR_MENU_ENTRY's, if you are an advanced programmer,
  11674.   you will find other ways in assigning the colors.
  11675.  
  11676.  
  11677.   BarCreateMenu() function
  11678.   ------------------------
  11679.  
  11680.   Now that you have created the BAR_MENU_ENTRY's, and defined the color
  11681.   scheme, it is time to wrap all of these loose ends in one package.  The next
  11682.   step is to call the BarCreateMenu() function.  This function combines all
  11683.   of the BAR_MENU_ENTRY's, the colors you have defined, and other information
  11684.   into one entity called a BAR_MENU_PTR.
  11685.  
  11686.   A BAR_MENU_PTR is a bar menu structure.  Just like a WPOINTER is a
  11687.   pointer to a window, a BAR_MENU_PTR is used to reference the bar menu.
  11688.  
  11689.   A prototype of the call to BarCreateMenu() is as follows:
  11690.  
  11691.   BAR_MENU_PTR BarCreateMenu(BAR_MENU_ENTRY *b, unsigned *c, int row,
  11692.                                  int col, unsigned options,
  11693.                                  WPOINTER (*wfunc)())
  11694.  
  11695.   To illustrate how to use this call, let's use the BAR_MENU_ENTRY's and
  11696.   colors created in the previous examples:
  11697.  
  11698.   #include "menu.h"
  11699.   int menu_func();
  11700.  
  11701.   BAR_MENU_ENTRY bar_items[] = {
  11702.                                "File",1,4,'F',ALTF,NULLFN,
  11703.                                "Edit",1,10,'E',0,edit,
  11704.                                "Run",1,17,'R',0,NULLFN,
  11705.                                "Compile",1,23,'C',0,NULLFN,
  11706.                                "Project",1,33,'P',0,NULLFN,
  11707.                                "Options", 1,43,'O',0,NULLFN,
  11708.                                "Debug",1,53,'D',0,NULLFN,
  11709.                                "Break/watch",1,61,'B',0,NULLFN,
  11710.                                CWL_NULL};
  11711.  
  11712.  Page 198                     The C Window Library                    Page 198
  11713.  
  11714.   unsigned int menu_colors[5];
  11715.   BAR_MENU_PTR b;
  11716.  
  11717.   main()
  11718.   {
  11719.     WindowInitializeSystem();          /* Initialize C Window Library */
  11720.  
  11721.    /* define colors */
  11722.  
  11723.     menu_colors[ENTRYCOLOR] = CREATE_VIDEO_ATTRIBUTE(black,white);
  11724.     menu_colors[BORDERCOLOR] = CREATE_VIDEO_ATTRIBUTE(black,white);
  11725.     menu_colors[HOTKEYCOLOR] = CREATE_VIDEO_ATTRIBUTE(blue,white);
  11726.     menu_colors[HIGHLIGHTCOLOR] = CREATE_VIDEO_ATTRIBUTE(black,cyan);
  11727.     menu_colors[UNAVAILCOLOR] = CREATE_VIDEO_ATTRIBUTE(white,black);
  11728.  
  11729.    /* create a BAR_MENU_PTR */
  11730.  
  11731.    WindowSaveInitial(0);  /* Save initial screen    */
  11732.    b = BarCreateMenu(menu_items,menu_colors,1,1,NO_BAR_OPTIONS,WNULLFN);
  11733.   /* rest of the code */
  11734.   }
  11735.  
  11736.  
  11737.   In the example above there are two function calls that must be done before
  11738.   calling BarCreateMenu().  The first mandatory function is
  11739.   WindowInitializeSystem().  The other function must be WindowSaveInitial()
  11740.   The WindowInitializeSystem() function must be called to initialize global
  11741.   variables used by the menu manager.  The WindowSaveInitial() function is a
  11742.   mandatory function because the BarCreateMenu() function creates windows and
  11743.   assumes that the base screen has been saved.
  11744.  
  11745.  
  11746.   The example above declares the variable b to be a BAR_MENU_PTR.  This
  11747.   BAR_MENU_PTR is going to be used to reference the bar menu throughout the
  11748.   program.
  11749.  
  11750.   The first argument is a pointer to the first BAR_MENU_ENTRY.  In the above
  11751.   example,  menu_items is a pointer to the first BAR_MENU_ENTRY.
  11752.  
  11753.   The second argument is a pointer to the array of colors.  In our example,
  11754.   menu_colors is our array of colors.
  11755.  
  11756.   The third and fourth arguments denote the row and column to place the upper
  11757.   left hand corner of the bar menu window.
  11758.  
  11759.   The fifth argument are various bar menu options that are assigned to the
  11760.   bar menus which are defined below.
  11761.  
  11762.  
  11763.  
  11764.  
  11765.  
  11766.  
  11767.  
  11768.  Page 199                     The C Window Library                    Page 199
  11769.  
  11770.   Bar Menu Options
  11771.   ----------------
  11772.  
  11773.   By default the menu manager assumes the following things:
  11774.  
  11775.     1)  The highlight bar does not wrap if the user wants to move the bar past
  11776.         the last entry, or before the first entry.
  11777.  
  11778.     2)  The menu will be hidden from the screen when a selection is made and
  11779.         will reappear when control is returned to the menu manager.
  11780.  
  11781.     3)  A function is automatically invoked when the hotkey is pressed instead
  11782.         of calling a user-defined function which will tell the menu manager
  11783.         whether the menu entry is to be executed.
  11784.  
  11785.     4)  The bar menu window is hidden when the menu manager returns control
  11786.         to the calling function.
  11787.  
  11788.     5)  The highlight bar will skip unavailable entries.
  11789.  
  11790.     6)  The menu manager does not recognize enhanced keys (F11, F12, etc.).
  11791.  
  11792.     7)  The mouse will not be used to move the highlight bar.
  11793.  
  11794.     8)  Scroll characters will not be displayed on the bar window.  The
  11795.         scroll characters allow the user to scroll through the options with a
  11796.         mouse.
  11797.  
  11798.  
  11799.   The last two options are only available if you have a Microsoft compatible
  11800.   mouse, and the mouse is activated.
  11801.  
  11802.   If the constant NO_BAR_OPTIONS is used, the assumptions above are used.  If
  11803.   you want to override the above defaults, use the following options:
  11804.  
  11805.      Option Name              Definition
  11806.      -----------              ----------
  11807.       BARWRAP             Highlight bar wrapping.
  11808.       BARSTATIC           Do not hide menu when selection is made.
  11809.       BARCONFIRM          Confirmation when selection is made via hotkey.
  11810.       BARDISPLAY          Display menu even after exit.
  11811.       BAROVERRIDE         Accept Unavailable entries.
  11812.       BARENHANCEDKEY      Recognize enhanced keys.
  11813.       BARMOUSE            Use the mouse to select entries.
  11814.  
  11815.   As was stated before, the last option, BARMOUSE  can only be used if you have
  11816.   a mouse installed, and the mouse is activated.  More information on these two
  11817.   options is given in the USING THE MOUSE section.
  11818.  
  11819.  
  11820.   By turning the above options "on" the following is assumed:
  11821.  
  11822.  
  11823.  
  11824.  Page 200                     The C Window Library                    Page 200
  11825.  
  11826.     1)  BARWRAP will wrap the highlight bar if the user wants to move the bar
  11827.         past the last entry or before the first entry.
  11828.  
  11829.     2)  BARSTATIC will not hide the menu when a selection is made.
  11830.  
  11831.     3)  BARCONFIRM will call a user-defined function before invoking the
  11832.         hotkey that was selected.  This function will then return an integer
  11833.         back to the menu manager informing whether the function selected should
  11834.         be invoked, or the request should be rejected.  There is more
  11835.         information on this option in the SETTING OPTIONS IN BAR MENUS
  11836.         section below.
  11837.  
  11838.     4)  BARDISPLAY will not hide the bar window when the menu manager
  11839.         returns control to the calling function.
  11840.  
  11841.     5)  BAROVERRIDE will make the menu manager accept unavailable entries.
  11842.  
  11843.     6)  BARENHANCEDKEY will inform the menu manager that enhanced keys will
  11844.         be recognized.
  11845.  
  11846.     7)  BARMOUSE allows the use of a mouse to make selections.
  11847.  
  11848.   You can also set multiple options by using a bitwise OR (|).  For example:
  11849.  
  11850.     b = BarCreateMenu(arg1,arg2,arg3,arg4,BARWRAP | BARSTATIC | BARCONFIRM,
  11851.                       arg5)
  11852.  
  11853.   will set options BARWRAP, BARSTATIC, and BARCONFIRM defined above.
  11854.  
  11855.   The last argument to BarCreateMenu() is defined in the next sections.
  11856.  
  11857.  
  11858.  
  11859.   Default Bar Menu Window and Creating Your own Windows
  11860.   -----------------------------------------------------
  11861.  
  11862.   The sixth argument to the BarCreateMenu() function is a pointer to a
  11863.   function that will open a bar menu window.  If this is a NULL function
  11864.   pointer (WNULLFN), the menu manager will create a window.  For most
  11865.   applications, the window that the menu manager will create is adequate.  The
  11866.   menu manager uses these defaults when making the bar window:
  11867.  
  11868.      - A bordered window with the border consisting of single lines (SINGLEBOX).
  11869.      - The width of the window is determined by the longest row of entry names.
  11870.  
  11871.   If you want to create your own bar menu window, your function must return a
  11872.   WPOINTER.  Inside your function you must create and open a window using
  11873.   WindowInitialize() and WindowOpen().  For most applications, you do not have
  11874.   to display the window, instead the menu manager can do the displaying and
  11875.   hiding of the windows.
  11876.  
  11877.  
  11878.  
  11879.  
  11880.  Page 201                     The C Window Library                    Page 201
  11881.  
  11882.   Here is an example of creating your own custom window function:
  11883.  
  11884.   #include "menu.h"
  11885.   /* Other includes and menu stuff */
  11886.   WPOINTER my_open();
  11887.   BAR_MENU_PTR b;
  11888.  
  11889.   main()
  11890.   {
  11891.      /*   Other code */
  11892.      b = BarCreateMenu(menu_items,menu_colors,1,1,NO_BAR_OPTIONS,my_open);
  11893.      /* More code */
  11894.   }
  11895.  
  11896.  
  11897.  
  11898.   WPOINTER my_open()
  11899.   {
  11900.     WPOINTER w;
  11901.     w = WindowInitialize(NOBORDER,1,1,80,1,BLACKONWHITE,BLACKONWHITE,"");
  11902.     WindowOpen(w);
  11903.     return w;       /* May be null pointer,
  11904.                        but must return to BarCreateMenu() */
  11905.   }
  11906.  
  11907.  
  11908.   The example above lets the menu manager know that the window creation
  11909.   function is a user written function called my_open.  The row, column and
  11910.   height arguments (arguments 3 and 4) of BarCreateMenu() will be ignored
  11911.   when using a custom window function.  The row and column height parameters
  11912.   used to create the window in the call to WindowInitialize() in my_window()
  11913.   will take precedence over the arguments 3 and 4 used in BarCreateMenu().
  11914.  
  11915.   It is the programmer's responsibility to make sure that the window that is
  11916.   created is wide and tall enough to hold all of the menu entries.  If not, the
  11917.   results will be unpredictable.
  11918.  
  11919.  
  11920.  
  11921.   Accessing bar menu windows
  11922.   --------------------------
  11923.  
  11924.   After calling the BarCreateMenu() function, you can access the bar window
  11925.   by using the BAR_WINDOW() macro.  In the above example, b is the
  11926.   BAR_MENU_PTR and the value of BAR_WINDOW(b) is a pointer to the bar
  11927.   menu's window.  If you want to change borders move, slide, or anything you
  11928.   can do with normal windows, you must access the bar window in this way.
  11929.  
  11930.   For example, if you want to change the border of the bar window you would
  11931.   do the following:
  11932.  
  11933.  
  11934.  
  11935.  Page 202                     The C Window Library                    Page 202
  11936.  
  11937.       b = BarCreateMenu(...  /* other arguments */ )
  11938.       WindowDrawBorder(BAR_WINDOW(b),DOUBLEBOX);  /* change border to a
  11939.                                                        double lined box */
  11940.  
  11941.   The example calls WindowDrawBorder() to change the border of the bar
  11942.   window.
  11943.  
  11944.  
  11945.  
  11946.   Warnings
  11947.   --------
  11948.  
  11949.   Do not call WindowFree(), WindowClose() on the window of the bar menu.  The
  11950.   menu manager will call these functions when BarMenuFree() is called.  If you
  11951.   close the bar window on an active menu, the menu manager will assume that the
  11952.   bar window still exists.  Doing so will almost guarantee your application
  11953.   will bomb out.
  11954.  
  11955.  
  11956.  
  11957.   Return Values for BarCreateMenu()
  11958.   ---------------------------------
  11959.  
  11960.   If there are no errors, BarCreateMenu() returns a valid BAR_MENU_PTR
  11961.   pointer.  If there is an error when BarCreateMenu() is called, a null
  11962.   BAR_MENU_PTR is returned.  Here are the possible reasons why an error has
  11963.   occurred:
  11964.  
  11965.     1) There is not enough memory to allocate for the BAR_MENU_PTR or its
  11966.        internal data structures.
  11967.  
  11968.     2) There is not enough memory to allocate for the bar window.
  11969.  
  11970.     3) The bar window's size was invalid.
  11971.  
  11972.   Problems 1 and 2 all are caused by a lack of heap memory.  Problem 3 stems
  11973.   from having invalid parameters in the BarCreateMenu().  The arguments that
  11974.   are suspect are the third and fourth.  To remedy this problem, adjust these
  11975.   arguments such that the window can fit on the screen.
  11976.  
  11977.   For all of the above conditions, you can get the actual error code by
  11978.   checking the value of the global integer window_error_code.  If
  11979.   window_error_code is equal to NO_HEAP_MEM, then condition 1 or 2 has
  11980.   occurred.  If it is equal to BAD_WINDOW_SIZE, then condition 3 has occurred.
  11981.  
  11982.   If you have a custom window opening function, it is your responsibility to
  11983.   check the error conditions that may occur, and return a correct value or a
  11984.   null pointer if you cannot rectify the error in your custom routine.
  11985.  
  11986.  
  11987.  
  11988.  
  11989.  
  11990.  
  11991.  Page 203                     The C Window Library                    Page 203
  11992.  
  11993.   Here is an example:
  11994.  
  11995.   Example:
  11996.        int status;
  11997.        BAR_MENU_PTR b;
  11998.        b = BarCreateMenu(...);
  11999.        if (b == (BAR_MENU_PTR)0)  {   /* check for null BAR_MENU_PTR pointer */
  12000.          if (window_error_code == NO_HEAP_MEM)
  12001.             /* ... Condition 1 or 2 occurred */
  12002.          else
  12003.            /* Condition 3 occurred */
  12004.        }
  12005.  
  12006.  
  12007.  
  12008.  
  12009.  
  12010.  
  12011.  
  12012.  
  12013.  
  12014.  
  12015.  
  12016.  
  12017.  
  12018.  
  12019.  
  12020.  
  12021.  
  12022.  
  12023.  
  12024.  
  12025.  
  12026.  
  12027.  
  12028.  
  12029.  
  12030.  
  12031.  
  12032.  
  12033.  
  12034.  
  12035.  
  12036.  
  12037.  
  12038.  
  12039.  
  12040.  
  12041.  
  12042.  
  12043.  
  12044.  
  12045.  
  12046.  
  12047.  Page 204                     The C Window Library                    Page 204
  12048.  
  12049.                           SELECTING FROM BAR MENUS
  12050.                           ------------------------
  12051.  
  12052.   We have now created the bar menu.  Now how do we get the menu manager to
  12053.   act on our bar window?  The answer is the BarSelectMenu() function.
  12054.  
  12055.  
  12056.   BarSelectMenu() function
  12057.   ------------------------
  12058.  
  12059.   The BarSelectMenu() function displays the bar window, and allows the
  12060.   user to move the highlight bar until he/she has placed the bar on the desired
  12061.   entry, or the user presses a hotkey to invoke one of the entries.
  12062.  
  12063.   Before the call to the BarSelectMenu(), nothing has been displayed.  This
  12064.   means that you can resize the bar window, change borders etc. while
  12065.   everything is hidden away from view.  The only time when the bar menu is
  12066.   displayed is when the call to BarSelectMenu() is made (or unless you have
  12067.   displayed the bar window yourself using WindowDisplay()).
  12068.  
  12069.   A prototype of the call to BarSelectMenu() is as follows:
  12070.  
  12071.        int BarSelectMenu(BAR_MENU_PTR b, int rank, unsigned start)
  12072.  
  12073.   The first argument is the BAR_MENU_PTR.  The second argument is the rank of
  12074.   the bar window.  As with other windows, the rank determines how the window
  12075.   will be situated on the screen with respect to the other windows.  The last
  12076.   argument is the number of the menu entry of where the highlight bar should be
  12077.   situated.  Usually this is 1, but this will give you the option to start on
  12078.   any one of the menu entries.  If the start value is out of bounds (say you
  12079.   have specified start to be 5 while there are only 4 menu entries) the menu
  12080.   manager will default to the first menu entry.
  12081.  
  12082.   Now let's put everything together:
  12083.  
  12084.   #include "menu.h"
  12085.  
  12086.   int menu_func();
  12087.  
  12088.   BAR_MENU_ENTRY bar_items[] = {
  12089.                                "File",1,4,'F',ALTF,menu_func,
  12090.                                "Edit",1,10,'E',0,menu_func,
  12091.                                "Run",1,17,'R',0,menu_func,
  12092.                                "Compile",1,23,'C',0,menu_func,
  12093.                                "Project",1,33,'P',0,menu_func,
  12094.                                "Options", 1,43,'O',0,menu_func,
  12095.                                "Debug",1,53,'D',0,menu_func,
  12096.                                "Break/watch",1,61,'B',0,menu_func,
  12097.                                CWL_NULL};
  12098.  
  12099.  
  12100.  
  12101.  
  12102.  
  12103.  Page 205                     The C Window Library                    Page 205
  12104.  
  12105.   unsigned int menu_colors[5];
  12106.   BAR_MENU_PTR b;
  12107.  
  12108.   main()
  12109.   {
  12110.     WindowInitializeSystem();
  12111.     WindowSaveInitial(0);  /* Remember to save the initial screen */
  12112.     menu_colors[ENTRYCOLOR] = CREATE_VIDEO_ATTRIBUTE(white,black);
  12113.     menu_colors[BORDERCOLOR] = CREATE_VIDEO_ATTRIBUTE(white,black);
  12114.     menu_colors[HOTKEYCOLOR] = CREATE_VIDEO_ATTRIBUTE(white,blue);
  12115.     menu_colors[HIGHLIGHTCOLOR] = CREATE_VIDEO_ATTRIBUTE(cyan,black);
  12116.     menu_colors[UNAVAILCOLOR] = CREATE_VIDEO_ATTRIBUTE(white,black);
  12117.    /* create a BAR_MENU_PTR */
  12118.    b = BarCreateMenu(bar_items,menu_colors, 1,1,BARSTATIC | BARWRAP,WNULLFN);
  12119.    BarSelectMenu(b,1,1);
  12120.   }
  12121.  
  12122.   int menu_func(BAR_MENU_PTR b, unsigned which)
  12123.   {
  12124.     WPOINTER w;
  12125.     w = WindowInitialize(BORDER,15,15,40,4,CREATE_VIDEO_ATTRIBUTE(black,white),
  12126.                          CREATE_VIDEO_ATTRIBUTE(black,white), SINGLEBOX);
  12127.     WindowOpen(w);
  12128.     WindowPrintf(w,"You have selected %s",BAR_ENTRY_STRING(b,which));
  12129.     WindowWriteCenterString(w,"Press a key to continue",3);
  12130.     WindowDisplay(w,1,NOEFFECT);
  12131.     GET_KEY();
  12132.     WindowFree(w,NOEFFECT);
  12133.     if (which == 9)
  12134.       return BAR_EXIT;
  12135.     else return BAR_CONTINUE;
  12136.   }
  12137.  
  12138.   The above example has a call to BarSelectMenu().  The arguments passed are
  12139.   b as the BAR_MENU_PTR, a window rank of 1, and a starting position of 1.  The
  12140.   BAR_ENTRY_STRING() macro that is called in menu_func() returns the entry
  12141.   string of a desired entry in a BAR_MENU_PTR.  The first argument is the
  12142.   BAR_MENU_PTR, and the second argument is the entry number of the entry
  12143.   desired.
  12144.  
  12145.  
  12146.   Values passed to menu function
  12147.   ------------------------------
  12148.  
  12149.   When a selection is made, the menu manager will call the function defined
  12150.   for the selection, and pass two arguments to this function.  The first
  12151.   argument passed is the BAR_MENU_PTR of the current bar menu and the
  12152.   second argument is the number of the item selected.  Item numbers are
  12153.   numbered from 1 to the highest entry in the menu.  For example, if the "File"
  12154.   entry is selected, the menu manager will pass the BAR_MENU_PTR b, and a
  12155.   1 to func().  If "Edit" is chosen, the menu manager passes a 2 as the
  12156.   second argument to func() etc.
  12157.  
  12158.  
  12159.  Page 206                     The C Window Library                    Page 206
  12160.  
  12161.   Values returned to menu manager
  12162.   -------------------------------
  12163.  
  12164.   The user function must return an integer back to the menu manager.  If the
  12165.   value returned to the menu manager is BAR_EXIT, the menu manager will exit
  12166.   from the current menu and will return control back to the function that
  12167.   called it.  If the return value is BAR_CONTINUE, the menu continues to
  12168.   process selections.
  12169.  
  12170.   The menu_func() function defined above creates a window, displays the entry
  12171.   you have chosen, and returns a value back to the menu manager.  If the value
  12172.   is BAR_EXIT, the menu manager returns control back to the function that
  12173.   called it.  In this case, main() called BarSelectMenu().  A return value of
  12174.   BAR_CONTINUE will cause the menu manager to let the user make another
  12175.   selection.
  12176.  
  12177.   The menu_func() function is a simple implementation.  However your function
  12178.   can do much more sophisticated things, including opening other bar menus.  If
  12179.   another bar menu is called while in another bar menu, the new bar menu gets
  12180.   its own menu manager and will not interfere with the original menu manager.
  12181.   This is good if a menu function will call another menu function.
  12182.  
  12183.  
  12184.  
  12185.   Return Values for BarSelectMenu()
  12186.   ---------------------------------
  12187.  
  12188.   If no errors occurred when BarSelectMenu() is called the menu manager
  12189.   returns NO_ERROR when the menu is closed.  There are three possibilities for
  12190.   errors when calling BarSelectMenu().  Here are the three possible errors:
  12191.  
  12192.   1) The bar menu's window does not exist.
  12193.  
  12194.   2) The bar menu's window is not opened.
  12195.  
  12196.   The first error occurred because the BarCreateMenu() function or your
  12197.   custom window function could not initialize the bar menu window, you
  12198.   inadvertently called WindowFree() on the bar menu's window, or you are
  12199.   overwriting data with a stray pointer.
  12200.  
  12201.   Error 2 can occur if the you inadvertently called WindowClose() on the bar
  12202.   menu's window, or you are overwriting data with a stray pointer.
  12203.  
  12204.   For all of the above conditions, you can get the actual error code by
  12205.   checking the value of the global integer window_error_code or by checking
  12206.   the return value of BarSelectMenu().  Here is a list of return values and
  12207.   their corresponding reasons:
  12208.  
  12209.  
  12210.     Return Value               Condition
  12211.     ------------               ---------
  12212.     BAD_WINDOW                    1
  12213.     WINDOW_NOT_OPEN               2
  12214.  
  12215.  Page 207                     The C Window Library                    Page 207
  12216.  
  12217.                          SETTING OPTIONS IN BAR MENUS
  12218.                          ----------------------------
  12219.  
  12220.   In addition to setting options using the BarCreateMenu() function, you can
  12221.   turn on and off options at any time using the BarSetOptions() function.
  12222.  
  12223.  
  12224.   The BarSetOptions() function
  12225.   ----------------------------
  12226.  
  12227.   The BarSetOptions() function turns either one or more of the above
  12228.   options on or off.  The prototype to the call is as follows:
  12229.  
  12230.          int BarSetOptions(BAR_MENU_PTR b, int option, int switch)
  12231.  
  12232.   The first argument is the BAR_MENU_PTR.  The second argument are the options
  12233.   that you wish to change.  The constants that describe the options are exactly
  12234.   the same as the ones described in BarCreateMenu().  The third argument is
  12235.   whether you want to switch the options on or off.
  12236.  
  12237.     Here are some sample calls to BarSetOptions():
  12238.  
  12239.       a) BarSetOptions(b,BARWRAP,1)
  12240.       b) BarSetOptions(b,BARSTATIC,1)
  12241.       c) BarSetOptions(b,BARCONFIRM,1)
  12242.       d) BarSetOptions(b,BARSTATIC,0)
  12243.       e) BarSetOptions(b,BARDISPLAY,1)
  12244.       f) BarSetOptions(b,BAROVERRIDE,1)
  12245.       g) BarSetOptions(b,BARENHANCEDKEY,1)
  12246.  
  12247.   The third argument is 1 for "on", 0 for "off".
  12248.  
  12249.   Example a) sets the highlight bar so that it will wrap.
  12250.  
  12251.   Example b) informs the menu manager that the menu will not be hidden when a
  12252.   selection is made.
  12253.  
  12254.   Example c) will tell the menu manager to call a user defined function that
  12255.   will inform the menu manager whether to invoke the selection in the menu.
  12256.  
  12257.   Example d) Informs the menu manager to hide the menu window when a menu
  12258.   function is invoked.
  12259.  
  12260.   Example e) Informs the menu manager not to hide the menu when control is
  12261.   returned to the function that called BarSelectMenu().
  12262.  
  12263.   Example f) Informs the menu manager to process unavailable entries.  This is
  12264.   useful if you want to set up your own error routine if the user selects an
  12265.   unavailable entry.
  12266.  
  12267.   Example g) imforms the menu manager to distinguish between normal keys and
  12268.   enhanced keys.
  12269.  
  12270.  
  12271.  Page 208                     The C Window Library                    Page 208
  12272.  
  12273.   Setting Multiple Options
  12274.   ------------------------
  12275.   You can also set multiple options with a single call by using a bitwise OR
  12276.   (|).  For example:
  12277.  
  12278.     BarSetOptions(b,BARWRAP | BARSTATIC | BARCONFIRM,1)
  12279.  
  12280.   will set options BARWRAP, BARSTATIC, and BARCONFIRM defined above.
  12281.  
  12282.  
  12283.  
  12284.   Setting the BarSetConfirmFunction()
  12285.   -----------------------------------
  12286.  
  12287.   When using the BARCONFIRM option, you must also use the
  12288.   BarSetConfirmFunction() function to point the menu to the confirmation
  12289.   function that will be called when a hotkey is pressed.  Here is a prototype
  12290.   of the BarSetConfirmFunction():
  12291.  
  12292.            BarSetConfirmFunction(BAR_MENU_PTR b, int (*func)())
  12293.  
  12294.   where b is the desired bar menu to assign the confirmation function to,
  12295.   and func is a pointer to a function that will return a value back to the menu
  12296.   manager that will inform it to either invoke the option, or ignore the
  12297.   option.
  12298.  
  12299.   When the confirmation function is called, the menu manager passes three
  12300.   arguments to func.  The prototype for your user defined function should be as
  12301.   follows:
  12302.  
  12303.         int my_confirm_func(BAR_MENU_PTR b, unsigned key, unsigned sel)
  12304.  
  12305.   where b is the BAR_MENU_PTR that is currently being processed, key is
  12306.   the hotkey that was pressed, and sel is the selection where the highlight bar
  12307.   is now positioned.  The highlight bar is always positioned on the hotkey
  12308.   selection even if it may not be invoked.  This user defined function must
  12309.   return a value back to the menu manager.  The valid values that can be
  12310.   returned are BAR_CONTINUE and BAR_DO_CHOICE.  If BAR_CONTINUE is
  12311.   returned, the menu selection is not invoked, if BAR_DO_CHOICE is selected,
  12312.   the menu entry is invoked.  Here is an example:
  12313.  
  12314.      #include "menu.h"
  12315.  
  12316.      int my_confirm_func();
  12317.      BAR_MENU_PTR b;
  12318.      /* ... */
  12319.      main()
  12320.      {
  12321.        BarSetOptions(b,BARCONFIRM,1);
  12322.        BarSetConfirmFunction(b,my_confirm_func);
  12323.        /* ... */
  12324.      }
  12325.  
  12326.  
  12327.  Page 209                     The C Window Library                    Page 209
  12328.  
  12329.      my_confirm_func(BAR_MENU_PTR b, unsigned k, unsigned sel)
  12330.      {
  12331.        /* ... */
  12332.        if (k == 'C' || k == 'c' || k == ALTF)
  12333.          return BAR_CONTINUE;
  12334.        else
  12335.          return BAR_DO_CHOICE;
  12336.      }
  12337.  
  12338.   The above function invokes the menu selection if the hotkey that was pressed
  12339.   is not a 'C', 'c', or ALT-F.
  12340.  
  12341.   The confirmation function can do anything, including setting options in the
  12342.   bar menu, displaying other windows etc.
  12343.  
  12344.  
  12345.  
  12346.   Return Values for BarSetOptions() function
  12347.   ------------------------------------------
  12348.  
  12349.   You can use the BarSetOptions() function at any time, including before
  12350.   calling the BarSelectMenu() function.  If the option is not a valid option,
  12351.   the function returns NO_ERROR, but does not change anything.  If the switch
  12352.   is not 0 or 1, a 1 is assumed.
  12353.  
  12354.   If there is an error, the error conditions and reasons are the same as the
  12355.   BarSelectMenu() function defined above.
  12356.  
  12357.  
  12358.  
  12359.  
  12360.  
  12361.  
  12362.  
  12363.  
  12364.  
  12365.  
  12366.  
  12367.  
  12368.  
  12369.  
  12370.  
  12371.  
  12372.  
  12373.  
  12374.  
  12375.  
  12376.  
  12377.  
  12378.  
  12379.  
  12380.  
  12381.  
  12382.  
  12383.  Page 210                     The C Window Library                    Page 210
  12384.  
  12385.                    MAKING ENTRIES AVAILABLE AND UNAVAILABLE
  12386.                    ----------------------------------------
  12387.  
  12388.   There may be cases when a menu entry should be made unavailable.  The entry
  12389.   shows up in the menu, but it is a different color than the other entries, and
  12390.   the highlight bar will just skip over this unavailable entry.
  12391.  
  12392.  
  12393.   BarMakeEntryAvailable() and
  12394.   BarMakeEntryUnavailable() functions
  12395.   -----------------------------------
  12396.  
  12397.   With The C Window Library, you can make entries available and unavailable at
  12398.   any time.  The BarMakeEntryAvailable() and the BarMakeEntryUnavailable()
  12399.   functions perform these tasks.
  12400.  
  12401.   A prototype of the call to both of these functions is as follows:
  12402.  
  12403.         int BarMakeEntryAvailable(BAR_MENU_PTR b, unsigned entry)
  12404.         int BarMakeEntryUnavailable(BAR_MENU_PTR b, unsigned entry)
  12405.  
  12406.   The first argument is the BAR_MENU_PTR.  The second argument is the number
  12407.   of the entry that you wish to change.  Entry numbers range from 1 to the
  12408.   highest entry in the menu.
  12409.  
  12410.  
  12411.  
  12412.   BAROVERRIDE option
  12413.   ------------------
  12414.  
  12415.   If the BAROVERRIDE option is set (see above), the menu manager will still
  12416.   process unavailable entries.  You must turn off BAROVERRIDE by using the
  12417.   BarSetOptions() function if you do not want to process unavailable entries.
  12418.  
  12419.  
  12420.   Return Values for BarMakeEntryAvaialble() and
  12421.   BarMakeEntryUnavailable() functions
  12422.   ---------------------------------------------
  12423.  
  12424.   If there is no error, both of these functions return NO_ERROR.
  12425.   If there is an error, the following possibilities can occur:
  12426.  
  12427.   1) The error can be one of the errors defined above for the BarSelectMenu()
  12428.  
  12429.   2) The menu entry is invalid.
  12430.  
  12431.   Refer to the BarSelectMenu() return values and reasons for failure defined
  12432.   above for error condition 1).  If the error is 2), check to see if the entry
  12433.   number supplied is valid.  The entry number cannot be < 1 or greater than the
  12434.   number of selections in the bar menu.
  12435.  
  12436.   If error 2) has occurred, the BarMakeEntryAvailable() and the
  12437.   BarMakeEntryUnavailable() return MENU_ENTRY_INVALID.
  12438.  
  12439.  Page 211                     The C Window Library                    Page 211
  12440.  
  12441.                        CHANGING THE MENU OPTIONS STRING
  12442.                        --------------------------------
  12443.  
  12444.   There may be times when you want to change a BAR_MENU_ENTRY entry_name
  12445.   string.  For instance, you may have a menu entry with the following
  12446.   entry_name:
  12447.  
  12448.           "Default File Name     ABC.DAT"
  12449.  
  12450.  
  12451.   If the user selects this choice, the file name should change to another file
  12452.   name the user wants.  From there the menu should reflect the new choice the
  12453.   user has made.  Let's say the user has changed the default file name to
  12454.   DEF.DAT.  The menu then should say:
  12455.  
  12456.  
  12457.           "Default File Name     DEF.DAT"
  12458.  
  12459.  
  12460.  
  12461.  
  12462.   BarChangeEntryString() function
  12463.   -------------------------------
  12464.  
  12465.   How do you change the entry string?  One way is to fool around with the
  12466.   BAR_MENU_PTR's structure members, and change the string yourself.  This is
  12467.   not recommended for the novice to average C programmer, since it is not a good
  12468.   idea to change the structure members directly without a full understanding of
  12469.   the structure.
  12470.  
  12471.   A safer way is to call the BarChangeEntryString() function.  A prototype of
  12472.   this function is as follows:
  12473.  
  12474.      BarChangeEntryString(BAR_MENU_PTR b, unsigned entry, char *newstring)
  12475.  
  12476.   The first argument is the BAR_MENU_PTR.  The second argument is the number
  12477.   of the entry that you wish to change.  Entry numbers range from 1 to the
  12478.   highest entry in the menu.  The third argument is a pointer to the new
  12479.   character string.  Remember that the width of the bar menu's window is equal
  12480.   to the width of the longest line of entry_name entries, therefore
  12481.   newstring cannot exceed the boundaries of the bar menu window (unless you
  12482.   will called WindowResizeWidth() or WindowResizeHeight() to resize the window).
  12483.  
  12484.  
  12485.  
  12486.   Return Values for BarChangeEntryString() function
  12487.   -------------------------------------------------
  12488.  
  12489.   If there is no error, then NO_ERROR is returned.
  12490.  
  12491.   If there is an error, the error conditions and reasons are the same as the
  12492.   BarMakeEntryAvailable() function defined above.
  12493.  
  12494.  
  12495.  Page 212                     The C Window Library                    Page 212
  12496.  
  12497.                            REDEFINING THE MENU KEYS
  12498.                            ------------------------
  12499.  
  12500.  
  12501.   Setting Global Key Definitions and
  12502.   the bar_key_definition Array
  12503.   ----------------------------------
  12504.  
  12505.   You can redefine the keys used to control moving the highlight bar, accepting
  12506.   the menu choice, and exiting from the menu.  Here is a list of the default key
  12507.   mapping:
  12508.  
  12509.        Function                               Key             Constant
  12510.        --------                               ---              ------
  12511.      Move highlight bar right               Up Arrow        BAR_RIGHTKEY
  12512.      Move highlight bar left                Down Arrow      BAR_LEFTKEY
  12513.      Accept Menu Choice                     Enter           BAR_ACCEPTKEY
  12514.      Escape Bar menu                        Escape          BAR_QUITKEY
  12515.      Move To First Menu Item                Home            BAR_HOMEKEY
  12516.      Move to Last Menu Item                 End             BAR_ENDKEY
  12517.  
  12518.   The global array bar_key_definition contains the values of the default
  12519.   bar menu key definitions.  The names under the Constant heading are the
  12520.   offsets in the bar_key_definition array of where the key value for the
  12521.   function is defined.  For instance, the value for the "Move highlight bar up"
  12522.   function is located at bar_key_definition[BAR_RIGHTKEY].  You can change the
  12523.   values in bar_key_definition at any time, but make sure that a definition
  12524.   for "Escape Bar menu" always exists, and that there are no duplicate
  12525.   definitions (i.e.  the "Move highlight bar up" key definition is the same as
  12526.   the "Move highlight bar down" key definition).  When defining new key values,
  12527.   you should use the values defined in the keycodes.h header file for non-ascii
  12528.   keys.
  12529.  
  12530.  
  12531.  
  12532.   Setting Local Key Definitions
  12533.   -----------------------------
  12534.  
  12535.   Another way of redefining menu keys is to load your own array of key
  12536.   definitions with your desired values, and then calling the BarAssignKeys()
  12537.   function.  With this method, each menu can have different key definitions.
  12538.  
  12539.  
  12540.   BarAssignKeys() function
  12541.   ------------------------
  12542.  
  12543.   Here is a prototype of the BarAssignKeys() function:
  12544.  
  12545.               int BarAssignKeys(BAR_MENU_PTR b, unsigned *keys)
  12546.  
  12547.   where b is the BAR_MENU_PTR, and keys is an array of key definitions.  Here
  12548.   is a small code example:
  12549.  
  12550.  
  12551.  Page 213                     The C Window Library                    Page 213
  12552.  
  12553.   #include "menu.h"
  12554.  
  12555.   unsigned mykeys[8] = {CTRLR,CTRLL,RETURN,ESC,HOME,END};
  12556.   BAR_MENU_PTR b;
  12557.  
  12558.   /* Other stuff...*/
  12559.  
  12560.   main()
  12561.   {
  12562.     /* Assume b is initialized */
  12563.  
  12564.     BarAssignKeys(b,mykeys); /* Assigns my key definitions to bar menu b */
  12565.   }
  12566.  
  12567.   The above example uses the constants defined in keycodes.h to assign to the
  12568.   array mykeys.  Each position in the mykeys array uses the default key mapping
  12569.   explained above.  In other words, mykeys[BAR_RIGHTKEY] is CTRLR, etc.
  12570.  
  12571.  
  12572.  
  12573.   Return Values for BarAssignKeys() function
  12574.   ------------------------------------------
  12575.  
  12576.   If there is no error, then NO_ERROR is returned.
  12577.  
  12578.   If there is an error, the error conditions and reasons are the same as the
  12579.   BarSelectMenu() function defined above.
  12580.  
  12581.  
  12582.  
  12583.  
  12584.  
  12585.  
  12586.  
  12587.  
  12588.  
  12589.  
  12590.  
  12591.  
  12592.  
  12593.  
  12594.  
  12595.  
  12596.  
  12597.  
  12598.  
  12599.  
  12600.  
  12601.  
  12602.  
  12603.  
  12604.  
  12605.  
  12606.  
  12607.  Page 214                     The C Window Library                    Page 214
  12608.  
  12609.                            PROCESSING UNDEFINED KEYS
  12610.                            -------------------------
  12611.  
  12612.   If you are an advanced programmer and/or have experience in using other
  12613.   window/menu libraries, you may be wondering "how do I define a function that
  12614.   supplies context-sensitive help for each BAR_MENU_ENTRY?  There is no
  12615.   structure member in BAR_MENU_ENTRY that supplies this".  With The C Window
  12616.   Library, any key that is not recognized by the menu manager (i.e. the key
  12617.   struck does not invoke a menu option, move the highlight bar up or down, or
  12618.   ends processing of the menu) can be processed by calling a user written
  12619.   function.   The WindowGet...() family of functions allowed us to define a
  12620.   function that will be called if a key that has no current definition is
  12621.   pressed.  For bar menus, we can do the same thing.
  12622.  
  12623.  
  12624.   The bar_undef_key function pointer
  12625.   ----------------------------------
  12626.  
  12627.   The global function pointer, bar_undef_key, can point to a user written
  12628.   function that will be called when the menu manager encounters a key that is
  12629.   not defined.  The declaration for bar_undef_key is as follows:
  12630.  
  12631.     unsigned int (*bar_undef_key)(BAR_MENU_PTR b, unsigned int sel,
  12632.                                     unsigned int *choice)
  12633.  
  12634.   The user written function takes three arguments.  The first argument is a
  12635.   pointer to the bar menu that the menu manager is currently processing. The
  12636.   second argument is an integer that contains the value of the key that was
  12637.   pressed.  The third argument is a pointer to an integer that will contain the
  12638.   number of the menu choice to execute.  Initially, choice points to an integer
  12639.   that contains the current menu choice that the menu highlight bar is situated.
  12640.   For instance, if the highlight bar is on the first menu choice when an
  12641.   undefined key is pressed, *choice will be equal to 1.  If bar_undef_key is
  12642.   equal to a Null Function pointer (NULLFN), no user defined function is called.
  12643.   By default, bar_undef_key is assigned to NULLFN.
  12644.  
  12645.  
  12646.   Values returned to menu manager
  12647.   -------------------------------
  12648.  
  12649.   If bar_undef_key is assigned to a function, the function must return an
  12650.   integer back to the menu manager.  This integer value will tell the menu
  12651.   manager how to proceed.  Here is a list of the valid return values that the
  12652.   user written function can return:
  12653.  
  12654.  
  12655.  
  12656.  
  12657.  
  12658.  
  12659.  
  12660.  
  12661.  
  12662.  
  12663.  Page 215                     The C Window Library                    Page 215
  12664.  
  12665.     Return                         Action to
  12666.     Value                            Take
  12667.     ------                         ---------
  12668.    BAR_CONTINUE          No Action. Continue processing the bar menu.
  12669.    BAR_DO_CHOICE         Accept and invoke menu entry assigned to *choice.
  12670.    BAR_MOVE_CONTINUE     Move the highlight bar to menu entry assigned to
  12671.                               *choice and continue processing menu.
  12672.    BAR_ESCAPE            Escape the bar menu.
  12673.    BAR_MOVE_LEFT         Move to next bar menu.
  12674.    BAR_MOVE_RIGHT        Move to previous bar menu.
  12675.    BAR_MOVE_HOME         Move highlight to first available menu entry.
  12676.    BAR_MOVE_END          Move highlight to last available menu entry.
  12677.  
  12678.   A return value of BAR_CONTINUE is a "do nothing" command to the menu
  12679.   manager.
  12680.  
  12681.   If BAR_DO_CHOICE is returned to the menu manager, the integer assigned to
  12682.   the parameter *choice is used as the menu entry to invoke.  The highlight
  12683.   bar will automatically be moved to the menu choice specified, and the menu
  12684.   function will be called.  If BAR_MOVE_CONTINUE is returned to the menu
  12685.   manager, the highlight bar will be moved to the entry specified by the
  12686.   value of *choice, but no function is called.
  12687.  
  12688.   Return values of BAR_DO_CHOICE and BAR_MOVE_CONTINUE only work when the
  12689.   menu entry specified by *choice is an available entry or the BAROVERRIDE
  12690.   option is on , otherwise the menu manager just continues processing the
  12691.   bar menu.
  12692.  
  12693.  
  12694.   Here is an example of using a user defined function for the undefined keys:
  12695.  
  12696.  
  12697.   #include "menu.h"
  12698.  
  12699.   /*  Other includes */
  12700.  
  12701.   int user_func();
  12702.  
  12703.  
  12704.   main()
  12705.  
  12706.   {
  12707.     bar_undef_key = user_func;
  12708.  
  12709.     /* Other code */
  12710.   }
  12711.  
  12712.  
  12713.  
  12714.  
  12715.  
  12716.  
  12717.  
  12718.  
  12719.  Page 216                     The C Window Library                    Page 216
  12720.  
  12721.   unsigned int user_func(BAR_MENU_PTR b, unsigned sel, unsigned *choice)
  12722.   {
  12723.     switch(sel)
  12724.  
  12725.     {
  12726.       case F1:
  12727.         help(*choice);         /* call help function */
  12728.         return BAR_CONTINUE; /* return "do nothing" command to menu manager */
  12729.       case F2:
  12730.         *choice = 6;  /* let menu manager know to do choice 6 on the menu */
  12731.         return BAR_DO_CHOICE;     /* Also let menu manager know we are
  12732.                                      returning the "do the function assigned to
  12733.                                      *choice" command */
  12734.       default:
  12735.         return BAR_CONTINUE;
  12736.         /* let menu manager know not to do anything */
  12737.     }
  12738.   }
  12739.  
  12740.   int help(int choice)
  12741.   {  /* help function */
  12742.     switch (choice)
  12743.     {
  12744.       case 1:
  12745.         /* do context-sensitive help for entry 1 */
  12746.       break;
  12747.       case 2:
  12748.         /* do context-sensitive help for entry 2 */
  12749.       break;
  12750.        /* do more entries */
  12751.        /* ... */
  12752.     }
  12753.   }
  12754.  
  12755.   In the above example, if the user hits F1, a help function is called.  If you
  12756.   wanted to know how to incorporate a help function in the bar menus, here is
  12757.   the way to do it.
  12758.  
  12759.   If the user hits F2, the integer pointed to by choice is assigned a 6, and
  12760.   user_func() returns BAR_DO_CHOICE to the menu manager.  This tells the
  12761.   menu manager to invoke the function assigned to menu entry 6.
  12762.  
  12763.  
  12764.  
  12765.  
  12766.  
  12767.  
  12768.  
  12769.  
  12770.  
  12771.  
  12772.  
  12773.  
  12774.  
  12775.  Page 217                     The C Window Library                    Page 217
  12776.  
  12777.                               PRE-INPUT FUNCTION
  12778.                               ------------------
  12779.  
  12780.   With The C Window Library, you can define a function that will be performed
  12781.   just before the menu manager waits for the user to enter a keystroke.  This
  12782.   function can perform just about anything.
  12783.  
  12784.  
  12785.   Setting the global_bar_prefunc function pointer
  12786.   -------------------------------------------------
  12787.  
  12788.   The global_bar_prefunc function pointer points to this user written
  12789.   function.  Here is the prototype:
  12790.  
  12791.       int (*global_bar_prefunc)(BAR_MENU_PTR p, unsigned *sel)
  12792.  
  12793.   The arguments that will be passed to your function are the following:
  12794.  
  12795.   a)  The BAR_MENU_PTR of the bar menu that called your function, and
  12796.  
  12797.   b)  A pointer to the number of the selection that the highlight bar is
  12798.       currently on.
  12799.  
  12800.   The selection number ranges from 1 to the highest entry number of the menu.
  12801.  
  12802.   The pre-input function MUST return a value back to the menu manager.  The
  12803.   return values that can be returned are the same as the bar_undef_key
  12804.   function described above.  If you are using a version of The C Window Library
  12805.   prior to version 1.5, you must declare your pre-input function as returning
  12806.   an int, and you must return a value back to the menu manager.  Versions prior
  12807.   to 1.5 declared the pre-input function as void.
  12808.  
  12809.   The BAR_DO_CHOICE and BAR_MOVE_CONTINUE return values will move the highlight
  12810.   bar to the entry number that is assigned to the *sel argument when the
  12811.   pre-input function has returned.
  12812.  
  12813.   By default, global_bar_prefunc points to a NULLFN, and therefore will not be
  12814.   performed.  However, you can implement pre-input functions depending on the
  12815.   current selection.  For instance, you can write a function that displays
  12816.   extra information for each entry like so:
  12817.  
  12818.   #include "menu.h"
  12819.  
  12820.   char *mess[] = {
  12821.                    " This option saves and loads files",
  12822.                    " This brings you in edit mode",
  12823.                    " This compiles and/or links the current program",
  12824.  
  12825.                    /* ... More stuff */
  12826.                    };
  12827.  
  12828.  
  12829.  
  12830.  
  12831.  Page 218                     The C Window Library                    Page 218
  12832.  
  12833.   WPOINTER message_window;
  12834.  
  12835.   int disp_info();
  12836.  
  12837.   main()
  12838.   {
  12839.     /* ... */
  12840.  
  12841.     global_bar_prefunc = disp_info;
  12842.  
  12843.     /* ... */
  12844.   }
  12845.  
  12846.   int disp_info(BAR_MENU_PTR p, unsigned *sel)
  12847.   {
  12848.      /* Assume message_window already created and opened */
  12849.  
  12850.     WindowClear(message_window,CREATE_VIDEO_ATTRIBUTE(black,white));
  12851.     WindowWriteString(message_window,mess[*sel-1],1,1);
  12852.     return BAR_CONTINUE;
  12853.   }
  12854.  
  12855.  
  12856.   For simplicity, the menu definitions are left out of the preceding code
  12857.   sample.  The disp_info displays the appropriate description in the window
  12858.   message_window.  BAR_CONTINUE is returned to the menu manager.  This
  12859.   informs the menu manager to continue looking for a keystroke.
  12860.  
  12861.  
  12862.  
  12863.  
  12864.  
  12865.  
  12866.  
  12867.  
  12868.  
  12869.  
  12870.  
  12871.  
  12872.  
  12873.  
  12874.  
  12875.  
  12876.  
  12877.  
  12878.  
  12879.  
  12880.  
  12881.  
  12882.  
  12883.  
  12884.  
  12885.  
  12886.  
  12887.  Page 219                     The C Window Library                    Page 219
  12888.  
  12889.                             DISPOSING OF BAR MENUS
  12890.                             ----------------------
  12891.  
  12892.   BarMenuFree() function
  12893.   ----------------------
  12894.  
  12895.   If the bar menu is no longer needed, the BarMenuFree() function will
  12896.   dispose of the bar menu and return any memory allocated to the bar menu,
  12897.   window, and  window memory back to the heap.  The call to the function
  12898.   is very simple:
  12899.  
  12900.          BarMenuFree(BAR_MENU_PTR b)
  12901.  
  12902.   where b is the BAR_MENU_PTR to dispose of.  Since this function destroys the
  12903.   BAR_MENU_PTR b, b must not be used for any bar menu functions, unless b
  12904.   is pointing to a valid BAR_MENU_PTR.
  12905.  
  12906.  
  12907.  
  12908.   Return Values for BarMenuFree()
  12909.   -------------------------------
  12910.  
  12911.   The return values and the reasons for failure are the same as
  12912.   BarSelectMenu().  Please refer to this section.
  12913.  
  12914.  
  12915.  
  12916.  
  12917.  
  12918.  
  12919.  
  12920.  
  12921.  
  12922.  
  12923.  
  12924.  
  12925.  
  12926.  
  12927.  
  12928.  
  12929.  
  12930.  
  12931.  
  12932.  
  12933.  
  12934.  
  12935.  
  12936.  
  12937.  
  12938.  
  12939.  
  12940.  
  12941.  
  12942.  
  12943.  Page 220                     The C Window Library                    Page 220
  12944.  
  12945.                                 PULLDOWN MENUS
  12946.                                 --------------
  12947.  
  12948.   Description
  12949.   -----------
  12950.  
  12951.   A pulldown menu is a combination of popup menus and a bar menu.  The bar menu
  12952.   portion of the pulldown menu acts the same way as a normal bar menu.  However
  12953.   when a choice is made from the bar menu, a popup menu appears with more
  12954.   options to choose.  An example of a pulldown menu is the integrated environ-
  12955.   ments of the Quick C and Turbo C compilers.
  12956.  
  12957.   Most of what was discussed previously will apply to pulldown menus.  Make
  12958.   sure that you have read the sections on popup menus and bar menus before
  12959.   preceding.
  12960.  
  12961.  
  12962.  
  12963.   Bar Menu and Popup Menu levels
  12964.   ------------------------------
  12965.  
  12966.   With pulldown menus there are two levels; the bar menu level and the popup
  12967.   menu level.  When in the bar menu level, no popup menu's are displayed, and
  12968.   the move right and move left keys move the highlight bar to the next or
  12969.   previous selection in the bar menu.  When in the popup menu level, the move
  12970.   right and move left keys not only move the highlight in the bar menu, but
  12971.   will also display the popup menu associated with the bar menu option.
  12972.  
  12973.  
  12974.  
  12975.  
  12976.  
  12977.  
  12978.  
  12979.  
  12980.  
  12981.  
  12982.  
  12983.  
  12984.  
  12985.  
  12986.  
  12987.  
  12988.  
  12989.  
  12990.  
  12991.  
  12992.  
  12993.  
  12994.  
  12995.  
  12996.  
  12997.  
  12998.  
  12999.  Page 221                     The C Window Library                    Page 221
  13000.  
  13001.                             CREATING PULLDOWN MENUS
  13002.                             -----------------------
  13003.  
  13004.  
  13005.   There are 4 steps that must be done when creating pulldown menus.  They are as
  13006.   follows:
  13007.  
  13008.      Step 1)  Create the bar menu portion by calling BarCreateMenu().
  13009.  
  13010.      Step 2)  Create each popup menu to be displayed underneath the bar by
  13011.               calling the PopupCreateMenu() function.
  13012.  
  13013.      Step 3)  Group all popup menus created in step 2 into an array of popup
  13014.               menu's.
  13015.  
  13016.      Step 4)  Call PulldownCreateMenu().
  13017.  
  13018.  
  13019.  
  13020.   For Step 1) the bar menu is created the same way as described in the Bar
  13021.   Menu section of this manual.  The only difference is that if there is a
  13022.   popup window that will be displayed under the bar menu option, the function
  13023.   pointer for that BAR_MENU_ENTRY must be a NULLFN (null integer function
  13024.   pointer).  Otherwise, if there is no popup menu defined for that bar menu
  13025.   option, the BAR_MENU_ENTRY's function pointer must point to a valid function.
  13026.   For instance, here is a sample array of BAR_MENU_ENTRY's used to create the
  13027.   Turbo C integrated environments bar menu:
  13028.  
  13029.  
  13030.     BAR_MENU_ENTRY bar_items[] = {
  13031.                 "File",       1,4, 'F',0,NULLFN,
  13032.                 "Edit",       1,10,'E',0,menu_func,
  13033.                 "Run",        1,17,'R',0,NULLFN,
  13034.                 "Compile",    1,23,'C',0,NULLFN,
  13035.                 "Project",    1,33,'P',0,NULLFN,
  13036.                 "Options",    1,43,'O',0,NULLFN,
  13037.                 "Debug",      1,53,'D',0,NULLFN,
  13038.                 "Break/watch",1,61,'B',0,NULLFN,
  13039.                           CWL_NULL};
  13040.  
  13041.   In the above example, All of the entries have a NULLFN function pointer except
  13042.   for the "Edit" entry.  The entries with NULLFN function pointers will have
  13043.   popup windows displayed under them when they are selected.  The "Edit" option
  13044.   will not have a popup menu displayed under it.  Instead, the menu_func()
  13045.   function is performed instead when "Edit" is chosen.
  13046.  
  13047.  
  13048.   Step 2) is as described in the Popup windows section.
  13049.  
  13050.   Step 3) can be done as follows:
  13051.  
  13052.  
  13053.  
  13054.  
  13055.  Page 222                     The C Window Library                    Page 222
  13056.  
  13057.   POPUP_MENU_PTR popup_list[8];
  13058.  
  13059.   main() {
  13060.   /* ... */
  13061.  
  13062.   popup_list[0] = PopupCreateMenu(/*..argument list..*/);
  13063.   popup_list[1] = (POPUP_MENU_PTR)0; /* No popup, so value must be NULL */
  13064.   popup_list[2] = PopupCreateMenu(/*..argument list..*/);
  13065.   popup_list[3] = PopupCreateMenu(/*..argument list..*/);
  13066.   popup_list[4] = PopupCreateMenu(/*..argument list..*/);
  13067.   popup_list[5] = PopupCreateMenu(/*..argument list..*/);
  13068.   popup_list[6] = PopupCreateMenu(/*..argument list..*/);
  13069.   popup_list[7] = PopupCreateMenu(/*..argument list..*/);
  13070.  
  13071.  
  13072.   The above example shows each element of popup_list is assigned to the return
  13073.   value of PopupCreateMenu(), except for popup_list[1].  Note that
  13074.   popup_list[1] is a null POPUP_MENU_PTR.  Here is the reason.  Let's say that
  13075.   there is an option on the bar menu that DOES NOT have a popup menu associated
  13076.   with it.  In other words, it is just a single function option, and no
  13077.   sub-functions are possible.  The entry in the array of POPUP_MENU_PTR's that
  13078.   will correspond to the position of where there is no popup menu should be
  13079.   NULL.  The above example shows that the second POPUP_MENU_PTR is non-existent
  13080.   (matches with the BAR_MENU_ENTRY called "Edit", which is the second bar
  13081.   entry).
  13082.  
  13083.   Once the bar menu and popup menus are created, you can set options by
  13084.   calling the BarSetOptions() or the PopupSetOptions() function, assign menu
  13085.   keys using the BarAssignKeys() or PopupAssignKeys() functions, etc. just as
  13086.   described earlier in this manual.  Remember that a pulldown menu just
  13087.   incorporates all of your menus into one manageable entity.
  13088.  
  13089.  
  13090.  
  13091.   The PulldownCreateMenu() function
  13092.   ---------------------------------
  13093.  
  13094.   The next step (Step 4) is done by calling the PulldownCreateMenu() function.
  13095.   This function integrates the bar menu and the array of popup menus in a
  13096.   single unit.  A pointer to this unit is returned.  This pointer is declared
  13097.   as a PULLDOWN_MENU_PTR.  The prototype form the PulldownCreateMenu() function
  13098.   is as follows:
  13099.  
  13100.          PULLDOWN_MENU_PTR PulldownCreateMenu(POPUP_MENU_PTR popups[],
  13101.                                               BAR_MENU_PTR bar,
  13102.                                               int adjust)
  13103.  
  13104.   The first argument is a pointer to an array of POPUP_MENU_PTR's.  In the
  13105.   above example, the second argument is the BAR_MENU_PTR.  Here is an example of
  13106.   how to use the PulldownCreateMenu() function:
  13107.  
  13108.  
  13109.  
  13110.  
  13111.  Page 223                     The C Window Library                    Page 223
  13112.  
  13113.   #include "menu.h"
  13114.  
  13115.   BAR_MENU_ENTRY bar_items[] = {
  13116.                 "File",       1,4, 'F',0,NULLFN,
  13117.                 "Edit",       1,10,'E',0,menu_func,
  13118.                 "Run",        1,17,'R',0,NULLFN,
  13119.                 "Compile",    1,23,'C',0,NULLFN,
  13120.                 "Project",    1,33,'P',0,NULLFN,
  13121.                 "Options",    1,43,'O',0,NULLFN,
  13122.                 "Debug",      1,53,'D',0,NULLFN,
  13123.                 "Break/watch",1,61,'B',0,NULLFN,
  13124.                           CWL_NULL};
  13125.  
  13126.  
  13127.   POPOP_MENU_ENTRY p1[] = {
  13128.                           /* Popup entries */,
  13129.                           CWL_NULL,0 };
  13130.  
  13131.   POPUP_MENU_ENTRY p2[] = POPUP_NULL_ENTRY; /* This constant defines an empty
  13132.                                                POPUP_MENU_ENTRY  */
  13133.  
  13134.   POPUP_MENU_ENTRY p3[] = {
  13135.                           /* More popup entries */
  13136.                         CWL_NULL, 0 };
  13137.  
  13138.   POPUP_MENU_ENTRY p4[] = {
  13139.                           /* More popup entries */
  13140.                         CWL_NULL, 0 };
  13141.  
  13142.  
  13143.   POPUP_MENU_ENTRY p5[] = {
  13144.                           /* More popup entries */
  13145.                         CWL_NULL, 0 };
  13146.  
  13147.   POPUP_MENU_ENTRY p6[] = {
  13148.                           /* More popup entries */
  13149.                         CWL_NULL, 0 };
  13150.  
  13151.   POPUP_MENU_ENTRY p7[] = {
  13152.                           /* More popup entries */
  13153.                         CWL_NULL, 0 };
  13154.  
  13155.   POPUP_MENU_ENTRY p7[] = {
  13156.                           /* More popup entries */
  13157.                         CWL_NULL, 0 };
  13158.  
  13159.   POPUP_MENU_PTR popup_list[8];
  13160.  
  13161.  
  13162.   BAR_MENU_PTR bar;
  13163.  
  13164.   PULLDOWN_MENU_PTR pull;
  13165.  
  13166.  
  13167.  Page 224                     The C Window Library                    Page 224
  13168.  
  13169.   main()
  13170.   {
  13171.     int i;
  13172.     WindowInitializeSystem();
  13173.     WindowSaveInitial(0);
  13174.     bar = BarCreateMenu(bar_items, { other arguments } );
  13175.  
  13176.     popup_list[0] = PopupCreateMenu(p1, { other arguments } );
  13177.     popup_list[1] = p2;
  13178.     popup_list[2] = PopupCreateMenu(p3, { other arguments } );
  13179.     popup_list[3] = PopupCreateMenu(p4, { other arguments } );
  13180.     popup_list[4] = PopupCreateMenu(p5, { other arguments } );
  13181.     popup_list[5] = PopupCreateMenu(p6, { other arguments } );
  13182.     popup_list[6] = PopupCreateMenu(p7, { other arguments } );
  13183.     popup_list[7] = PopupCreateMenu(p8, { other arguments } );
  13184.  
  13185.     pull = PulldownCreateMenu(popup_list,bar,1);
  13186.     {...}
  13187.   }
  13188.  
  13189.   In the above example, bar is a BAR_MENU_PTR, p1, p2, p3, p4, etc. are all
  13190.   lists of POPUP_MENU_ENTRY's.  The array of POPUP_MENU_PTR's is called
  13191.   popup_list, and the PULLDOWN_MENU_PTR is called pull.  Please note the use of
  13192.   the POPUP_NULL_ENTRY constant.  Use this constant when initializing a
  13193.   POPUP_MENU_ENTRY list to no items.
  13194.  
  13195.   The bar menu is initialized by calling BarCreateMenu() using bar_items as the
  13196.   list of BAR_MENU_ENTRY's.  The PopupCreateMenu() is called for each member of
  13197.   the popup_list array.  Note that the popup_list[1] is assigned a null
  13198.   POPUP_MENU_PTR.  This indicates that there is no popup menu for the second
  13199.   bar item ("Edit").  Even though it is not shown, you should check to see if
  13200.   BarCreateMenu() and all of the PopupCreateMenu() function calls returned
  13201.   without error.
  13202.  
  13203.   The call to PulldownCreateMenu() is done with the first argument being the
  13204.   the pointer to the array of POPUP_MENU_PTR's, namely popup_list.  The second
  13205.   argument is the BAR_MENU_PTR bar, and the last argument is discussed in the
  13206.   next section.
  13207.  
  13208.  
  13209.  
  13210.   Automatic Adjustment of Popup Windows
  13211.   -------------------------------------
  13212.  
  13213.   The last argument to PulldownCreateMenu() will inform the menu manager to
  13214.   adjust all the popup menu window positions, so that they fit neatly under the
  13215.   bar menu.  If the adjust argument in PulldownCreateMenu() is a 1, the
  13216.   previous (row,col) positions of each popup menu window is ignored
  13217.   (Arguments 3 and 4 of PopupCreateMenu()), and the menu manager decides where
  13218.   the popup window should be placed on the screen.  Otherwise, if adjust is 0,
  13219.   the previous values of the (row,col) position of the popup menu is used.
  13220.  
  13221.   Here is how the menu manager decides where the popup window should be placed:
  13222.  
  13223.  Page 225                     The C Window Library                    Page 225
  13224.  
  13225.   a)  The first attempt tries to place the left hand corner of the popup window
  13226.       under the first character of the option name in the bar menu.  If the
  13227.       column on the screen where we have placed the popup window, plus the
  13228.       popup windows width does not exceed the width of the bar, then we have
  13229.       found a "good" position for the popup window, if not then do step b).
  13230.  
  13231.   b)  We place the upper right hand corner of the popup window underneath the
  13232.       last column of the bar menu's window.  If the upper left-hand corner of
  13233.       the popup window can be placed in a screen column greater than or equal
  13234.       to 1, then we have found the "good" position.  If the upper left-hand
  13235.       corner cannot be placed in column 1 then do step c).
  13236.  
  13237.   c)  Place the upper left hand corner of the popup window at the first column
  13238.       of the bar menu window.  If this does not work then do step d).
  13239.  
  13240.   d)  place the popup window in column 1 of the screen.
  13241.  
  13242.   Here are a few examples of the above scenarios:
  13243.  
  13244.    1)
  13245.         -------------------------------------------------------------
  13246.         |  File      Edit      Compile      Options    Project      |
  13247.         |                                                           |
  13248.         -------------------------------------------------------------
  13249.           |            |
  13250.           |Condition a)|
  13251.           |  worked!   |
  13252.           |            |
  13253.           |------------|
  13254.  
  13255.    2a)
  13256.         -------------------------------------------------------------
  13257.         |  File      Edit      Compile      Options    Project      |
  13258.         |                                                           |
  13259.         ----------------------------------------------------------------------
  13260.                                             |                                |
  13261.                                             |  Too wide! option a) failed!   |
  13262.                                             |                                |
  13263.                                             |         Try option b)          |
  13264.                                             |                                |
  13265.                                             |--------------------------------|
  13266.  
  13267.    2b)
  13268.  
  13269.         -------------------------------------------------------------
  13270.         |  File      Edit      Compile      Options    Project      |
  13271.         |                                                           |
  13272.         -------------------------- ------------------------- --------                                   ----------
  13273.                                    |                                |
  13274.                                    |       option b) worked!        |
  13275.                                    |                                |
  13276.                                    |--------------------------------|
  13277.  
  13278.  
  13279.  Page 226                     The C Window Library                    Page 226
  13280.  
  13281.   In the first example, 1), the assumption is that the menu manager tries to
  13282.   place a popup window underneath the "File" in the bar menu.  It satisfies
  13283.   condition a), so we have found a good position.
  13284.  
  13285.   In the second example, 2a), the assumption is that the menu manager is trying
  13286.   to place a popup window under the "Compile" in the bar menu.   The first
  13287.   attempt fails because the popup window is too wide to be contained entirely
  13288.   in the bar menu.  We then try again to see if condition b) can be satisfied.
  13289.   Example 2b) shows that we can place the popup window according to condition
  13290.   b), and we have found a good condition.
  13291.  
  13292.   The other conditions, c) and d) should be self-explanatory at this point.
  13293.  
  13294.   Remember, if you do not like the way the menu manager selects the window
  13295.   position, you can either
  13296.  
  13297.   a)  specify the row and column positions of each popup menu window yourself
  13298.       when calling PopupCreateMenu(), and then calling PulldownCreateMenu()
  13299.       with a 0 (no adjustment) as the third argument or
  13300.  
  13301.   b)  Let the menu manager decide where to put the windows, and then adjust the
  13302.       positions yourself by calling WindowMove().
  13303.  
  13304.  
  13305.  
  13306.  
  13307.   Return values for PulldownCreateMenu()
  13308.   --------------------------------------
  13309.  
  13310.   If there is no error, PulldownCreateMenu() returns a valid PULLDOWN_MENU_PTR.
  13311.   If there is an error, PulldownCreateMenu() returns a null PULLDOWN_MENU_PTR.
  13312.  
  13313.   Here are the possible reasons why an error has occurred:
  13314.  
  13315.   1) There was not enough memory to allocate for the PULLDOWN_MENU_PTR or its
  13316.      internal data structures.
  13317.  
  13318.   2) The window for the bar menu did not exist.
  13319.  
  13320.   The first error results from a lack of heap memory.  If this error occurs,
  13321.   the global integer window_error_code will be set to NO_HEAP_MEM.
  13322.  
  13323.   If the second error occurs, this is an indication that the BAR_MENU_PTR was
  13324.   not created properly.  Check the return values for BarCreateMenu() if this
  13325.   happens.  The window_error_code is set to BAD_WINDOW if this error occurs.
  13326.  
  13327.   There is no check to see if the POPUP_MENU_PTR's are valid.  It is
  13328.   conceivable that there may be some entries on the bar that do not have popup
  13329.   menu's under them.  Therefore no check can be made for valid
  13330.   POPUP_WINDOW_PTR's.  It is the programmer's responsibility to check for
  13331.   invalid POPUP_MENU_PTR's when creating the popup menus.
  13332.  
  13333.  
  13334.  
  13335.  Page 227                     The C Window Library                    Page 227
  13336.  
  13337.                          SELECTING FROM PULLDOWN MENUS
  13338.                          -----------------------------
  13339.  
  13340.  
  13341.   The PulldownSelectMenu() function
  13342.   ---------------------------------
  13343.  
  13344.  
  13345.   The PulldownSelectMenu() allows selection from a pulldown menu.  This
  13346.   function has 6 arguments.  The prototype to this function is as follows:
  13347.  
  13348.       int PulldownSelectMenu(PULLDOWN_MENU_PTR pull, int barrank,
  13349.                              unsigned barstart, int *poprank,
  13350.                              unsigned *popstart, int imm)
  13351.  
  13352.  
  13353.   The first argument is a pointer to the PULLDOWN_MENU_PTR.  The second
  13354.   argument is the window rank of the bar menu window.  The third argument is
  13355.   the menu option where the bar menu should start beginning processing.  If the
  13356.   option is invalid or unavailable, the starting entry is the first available
  13357.   entry or the first entry if the BAROVERRIDE option is on for the bar menu.
  13358.  
  13359.   The fourth argument is an array of window ranks for each popup menu's window.
  13360.   This array will correspond to each of the popup menu's windows, including
  13361.   null popup menus.
  13362.  
  13363.   Example:
  13364.         int ranks[] = {1,1,1,1,1,1,1,1};
  13365.         unsigned start[] = {1,1,1,1,1,1,1,1};
  13366.  
  13367.         main() {
  13368.         /* ... */
  13369.           PulldownSelectMenu(pull,1,1,ranks,start,1);
  13370.  
  13371.         }
  13372.  
  13373.  
  13374.   The fifth argument is an array of starting entry numbers for each popup menu.
  13375.   This array will correspond to each of the popup menus, including NULL popup
  13376.   menus.  The previous example illustrates how this could be done.
  13377.  
  13378.  
  13379.  
  13380.   Immediate Mode
  13381.   --------------
  13382.  
  13383.   The last argument to PulldownSelectMenu() determines whether the menu will
  13384.   start in immediate mode.  Immediate mode will display the bar menu, and will
  13385.   also display the popup menu defined for the bar option.  If immediate mode
  13386.   is desired, the last argument is a 1, otherwise it is a 0.
  13387.  
  13388.  
  13389.  
  13390.  
  13391.  Page 228                     The C Window Library                    Page 228
  13392.  
  13393.   Values passed to the selected menu function
  13394.   -------------------------------------------
  13395.  
  13396.   When a selection is made, the menu manager will call the function defined
  13397.   for the selection, and pass five arguments to this function.  The first
  13398.   argument passed is the PULLDOWN_MENU_PTR of the current pulldown menu.  The
  13399.   second argument is the BAR_MENU_PTR of the pulldown menu.  The third argument
  13400.   is the POPUP_MENU_PTR of the selected entry.  If there is no popup menu,  the
  13401.   value passed for this argument is a NULL pointer.  The fourth argument is the
  13402.   number of the item selected on the bar menu.  The fifth argument is the
  13403.   number of the item selected on the popup menu.
  13404.  
  13405.  
  13406.  
  13407.   Values returned to the menu manager
  13408.   -----------------------------------
  13409.  
  13410.   Your function must return a value back to the menu manager.  There are two
  13411.   possible return values, PULLDOWN_EXIT and PULLDOWN_CONTINUE.
  13412.  
  13413.   The PULLDOWN_EXIT return value will cause the menu manager to close both the
  13414.   popup menu window (if one was displayed), and the bar menu.  Then control is
  13415.   returned back to the function that called PulldownSelectMenu().
  13416.  
  13417.   The PULLDOWN_CONTINUE return value will cause the menu manager to continue
  13418.   processing the pulldown menu without closing the popup window (if one was
  13419.   displayed).
  13420.  
  13421.  
  13422.   If the return value is not one of the ones mentioned above, PULLDOWN_CONTINUE
  13423.   is assumed.
  13424.  
  13425.  
  13426.  
  13427.   Return Values for PulldownSelectMenu()
  13428.   --------------------------------------
  13429.  
  13430.   If there are no errors, PulldownSelectMenu() returns NO_ERROR.
  13431.  
  13432.   If the bar menu window does not exist, PulldownSelectMenu() immediately
  13433.   returns with BAD_WINDOW.
  13434.  
  13435.   If the bar menu window is not open, PulldownSelectMenu() immediately returns
  13436.   with WINDOW_NOT_OPEN.
  13437.  
  13438.  
  13439.  
  13440.  
  13441.  
  13442.  
  13443.  
  13444.  
  13445.  
  13446.  
  13447.  Page 229                     The C Window Library                    Page 229
  13448.  
  13449.                           REDEFINING KEY DEFINITIONS
  13450.                           --------------------------
  13451.  
  13452.   The bar menu key definitions are invoked when the pulldown menu is at the bar
  13453.   menu level.  The popup menu keys are invoked when the pulldown menu is at the
  13454.   popup menu level.
  13455.  
  13456.   If the bar option does not have a popup menu associated with it, the bar menu
  13457.   keys are always used.
  13458.  
  13459.  
  13460.  
  13461.  
  13462.  
  13463.  
  13464.  
  13465.  
  13466.  
  13467.  
  13468.  
  13469.  
  13470.  
  13471.  
  13472.  
  13473.  
  13474.  
  13475.  
  13476.  
  13477.  
  13478.  
  13479.  
  13480.  
  13481.  
  13482.  
  13483.  
  13484.  
  13485.  
  13486.  
  13487.  
  13488.  
  13489.  
  13490.  
  13491.  
  13492.  
  13493.  
  13494.  
  13495.  
  13496.  
  13497.  
  13498.  
  13499.  
  13500.  
  13501.  
  13502.  
  13503.  Page 230                     The C Window Library                    Page 230
  13504.  
  13505.                   REDEFINING KEY DEFINITIONS FOR POPUP MENUS
  13506.                   ------------------------------------------
  13507.  
  13508.   Setting Popup Menu Global Key Definitions
  13509.   -----------------------------------------
  13510.  
  13511.   In the previous sections on popup menus, there was a global array of key
  13512.   definitions used for popup menus.  Recall that there were 3 key definitions
  13513.   that were not assigned.  These definitions were POPUP_RIGHTKEY,
  13514.   POPUP_LEFTKEY, and POPUP_PULLDOWN_QUIT.  When a popup menu is incorporated
  13515.   into a pulldown menu (after the PulldownCreateMenu() is called), the global
  13516.   array popup_key_definition is assigned the default values for these
  13517.   definitions.  Here are the default values for the popup portion of the
  13518.   pulldown menu:
  13519.  
  13520.  
  13521.        Function                      Key             Constant
  13522.        --------                      ---              ------
  13523.      Move highlight bar up         Up Arrow        POPUP_UPKEY
  13524.      Move highlight bar down       Down Arrow      POPUP_DOWNKEY
  13525.      Accept Menu Choice            Enter           POPUP_ACCEPTKEY
  13526.      Escape Pop-up menu            Escape          POPUP_QUITKEY
  13527.      Move To First Menu Item       Home            POPUP_HOMEKEY
  13528.      Move to Last Menu Item        End             POPUP_ENDKEY
  13529.      Move To Next Popup Menu       Right Arrow     POPUP_RIGHTKEY
  13530.      Move to Previous Popup Menu   Left Arrow      POPUP_LEFTKEY
  13531.      Escape Pulldown Menu          Not Assigned    POPUP_PULLDOWN_QUITKEY
  13532.  
  13533.   The global array popup_key_definition contains the values of the default
  13534.   popup menu key definitions.  The names under the Constant heading are the
  13535.   offsets in the popup_key_definition array of where the key value for the
  13536.   function is defined.  For instance, the value for the "Move highlight bar up"
  13537.   function is located at popup_key_definition[POPUP_UPKEY].  You can change the
  13538.   values in popup_key_definition at any time, but make sure that a definition
  13539.   for "Escape Pop-up menu" and/or "Escape Pulldown Menu" always exists, and
  13540.   that there are no duplicate definitions (i.e.  the "Move highlight bar up"
  13541.   key definition is the same as the "Move highlight bar down" key definition).
  13542.   When defining new key values, you should use the values defined in the
  13543.   keycodes.h header file for non-ascii keys.
  13544.  
  13545.   Also note that popup_key_definition[POPUP_PULLDOWN_QUITKEY] is not assigned.
  13546.   Since the key that is usually used to quit a pulldown menu is the Escape
  13547.   (ESC) key, and this definition conflicts with the "Escape Popup menu", it is
  13548.   better to let the programmer change the definition explicitly.
  13549.  
  13550.  
  13551.  
  13552.   Setting Popup Menu Local Definitions
  13553.   ------------------------------------
  13554.  
  13555.   You can use the PopupAssignKeys() function explained in the REDEFINING MENU
  13556.   KEYS section to redefine the popup menu keys for each popup menu.
  13557.  
  13558.  
  13559.  Page 231                     The C Window Library                    Page 231
  13560.  
  13561.  
  13562.  
  13563.  
  13564.  
  13565.  
  13566.  
  13567.  
  13568.                       This page intentionally left blank.
  13569.  
  13570.  
  13571.  
  13572.  
  13573.  
  13574.  
  13575.  
  13576.  
  13577.  
  13578.  
  13579.  
  13580.  
  13581.  
  13582.  
  13583.  
  13584.  
  13585.  
  13586.  
  13587.  
  13588.  
  13589.  
  13590.  
  13591.  
  13592.  
  13593.  
  13594.  
  13595.  
  13596.  
  13597.  
  13598.  
  13599.  
  13600.  
  13601.  
  13602.  
  13603.  
  13604.  
  13605.  
  13606.  
  13607.  
  13608.  
  13609.  
  13610.  
  13611.  
  13612.  
  13613.  
  13614.  
  13615.  Page 232                     The C Window Library                    Page 232
  13616.  
  13617.                 REDEFINING KEY DEFINITIONS FOR THE BAR MENU
  13618.                 -------------------------------------------
  13619.  
  13620.  
  13621.   Setting bar menu global key definitions
  13622.   ---------------------------------------
  13623.  
  13624.   You can redefine the keys used to control moving the highlight bar, accepting
  13625.   the menu choice, and exiting from the menu.  Here is a list of the default
  13626.   key mapping:
  13627.  
  13628.        Function                               Key             Constant
  13629.        --------                               ---              ------
  13630.      Move highlight bar right               Up Arrow        BAR_RIGHTKEY
  13631.      Move highlight bar left                Down Arrow      BAR_LEFTKEY
  13632.      Accept Menu Choice                     Enter           BAR_ACCEPTKEY
  13633.      Escape Bar menu (Escape Pulldown Menu) Escape          BAR_QUITKEY
  13634.      Move To First Menu Item                Home            BAR_HOMEKEY
  13635.      Move to Last Menu Item                 End             BAR_ENDKEY
  13636.  
  13637.  
  13638.  
  13639.   The global array bar_key_definition contains the values of the default
  13640.   bar menu key definitions.  The names under the Constant heading are the
  13641.   offsets in the bar_key_definition array of where the key value for the
  13642.   function is defined.  For instance, the value for the "Move highlight bar up"
  13643.   function is located at bar_key_definition[BAR_RIGHTKEY].  You can change the
  13644.   values in bar_key_definition at any time, but make sure that a definition
  13645.   for "Escape Bar menu" always exists, and that there are no duplicate
  13646.   definitions (i.e.  the "Move highlight bar up" key definition is the same as
  13647.   the "Move highlight bar down" key definition).  When defining new key values,
  13648.   you should use the values defined in the keycodes.h header file for non-ascii
  13649.   keys.
  13650.  
  13651.   Note that "Escape Bar Menu" will also escape the pulldown menu.
  13652.  
  13653.  
  13654.  
  13655.  
  13656.   Setting Bar Menu Local definitions
  13657.   ----------------------------------
  13658.  
  13659.   You can use the BarAssignKeys() function to redefine the bar menu keys.
  13660.  
  13661.  
  13662.  
  13663.  
  13664.  
  13665.  
  13666.  
  13667.  
  13668.  
  13669.  
  13670.  
  13671.  Page 233                     The C Window Library                    Page 233
  13672.  
  13673.                        PROCESSING UNDEFINED POPUP MENU KEYS
  13674.                        ------------------------------------
  13675.  
  13676.   Processing undefined keys is the same for regular popup menus, except that
  13677.   there are 3 new return values that can be used for popup menus that are
  13678.   incorporated in pulldown menus.
  13679.  
  13680.   The popup_undef_key function pointer acts the same way as described
  13681.   previously.  Here are the possible values that the function pointed to by
  13682.   popup_undef_key must return:
  13683.  
  13684.  
  13685.     Return                         Action to
  13686.     Value                            Take
  13687.     ------                         ---------
  13688.    POPUP_CONTINUE          No Action. Continue processing the popup menu.
  13689.    POPUP_MOVE_UP           Move the highlight bar up.
  13690.    POPUP_MOVE_DOWN         Move the highlight bar down.
  13691.    POPUP_DO_CHOICE         Accept and invoke menu entry assigned to *choice.
  13692.    POPUP_MOVE_CONTINUE     Move the highlight bar to menu entry assigned to
  13693.                               *choice and continue processing menu.
  13694.    POPUP_ESCAPE            Escape the popup menu.
  13695.    POPUP_MOVE_HOME         Move highlight to first available menu entry.
  13696.    POPUP_MOVE_END          Move highlight to last available menu entry.
  13697.    POPUP_MOVE_PAGEUP       Scroll the entries in the popup window up by one
  13698.                            "page" (a page is the current height of the popup
  13699.                            window).
  13700.    POPUP_MOVE_PAGEDOWN     Scroll the entries in the popup window down by one
  13701.                            "page" (a page is the current height of the popup
  13702.                            window).
  13703.    POPUP_MOVE_LEFT         Move to next popup menu.
  13704.    POPUP_MOVE_RIGHT        Move to previous popup menu.
  13705.    POPUP_PULLDOWN_QUIT     Escape pulldown menu
  13706.  
  13707.   Please note the new return values POPUP_MOVE_LEFT, POPUP_MOVE_RIGHT, and
  13708.   POPUP_PULLDOWN_QUIT.
  13709.  
  13710.  
  13711.  
  13712.  
  13713.  
  13714.  
  13715.  
  13716.  
  13717.  
  13718.  
  13719.  
  13720.  
  13721.  
  13722.  
  13723.  
  13724.  
  13725.  
  13726.  
  13727.  Page 234                     The C Window Library                    Page 234
  13728.  
  13729.                       PROCESSING UNDEFINED BAR MENU KEYS
  13730.                       ----------------------------------
  13731.  
  13732.   Here are the return values that the function pointed to by bar_undef_key must
  13733.   return.
  13734.  
  13735.     Return                         Action to
  13736.     Value                            Take
  13737.     ------                         ---------
  13738.    BAR_CONTINUE          No Action. Continue processing the bar menu.
  13739.    BAR_DO_CHOICE         Accept and invoke menu entry assigned to *choice, or
  13740.                               display popup menu underneath bar entry.
  13741.    BAR_MOVE_CONTINUE     Move the highlight bar to menu entry assigned to
  13742.                               *choice and continue processing menu.
  13743.    BAR_ESCAPE            Escape the bar menu (or pulldown menu).
  13744.    BAR_MOVE_LEFT         Move to next bar menu entry.
  13745.    BAR_MOVE_RIGHT        Move to previous bar menu entry.
  13746.    BAR_MOVE_HOME         Move highlight to first available menu entry.
  13747.    BAR_MOVE_END          Move highlight to last available menu entry.
  13748.  
  13749.  
  13750.   Please note that BAR_DO_CHOICE will either do the function assigned to the
  13751.   bar entry assigned to *choice, or display the popup menu underneath the bar
  13752.   menu entry assigned to *choice.
  13753.  
  13754.  
  13755.  
  13756.  
  13757.  
  13758.  
  13759.  
  13760.  
  13761.  
  13762.  
  13763.  
  13764.  
  13765.  
  13766.  
  13767.  
  13768.  
  13769.  
  13770.  
  13771.  
  13772.  
  13773.  
  13774.  
  13775.  
  13776.  
  13777.  
  13778.  
  13779.  
  13780.  
  13781.  
  13782.  
  13783.  Page 235                     The C Window Library                    Page 235
  13784.  
  13785.                      DISPOSING OF PULLDOWN MENUS
  13786.                      ---------------------------
  13787.  
  13788.   There are two functions that are used to dispose of pulldown menus.  The
  13789.   first is the PulldownMenuFree() function.
  13790.  
  13791.  
  13792.  
  13793.   The PulldownMenuFree() function
  13794.   -------------------------------
  13795.  
  13796.   The PulldownMenuFree() function disposes of the PULLDOWN_MENU_PTR and returns
  13797.   memory allocated back to the heap.  The bar menu and the popup menus
  13798.   associated with the pulldown menu remain intact.
  13799.  
  13800.   Here is a prototype of the call to PulldownMenuFree():
  13801.  
  13802.       int PulldownMenuFree(PULLDOWN_MENU_PTR pull)
  13803.  
  13804.  
  13805.  
  13806.  
  13807.   The PulldownMenuFreeAll() function
  13808.   ----------------------------------
  13809.  
  13810.  
  13811.   To dispose of the pulldown menu, the bar menu, and all of the popup menus,
  13812.   use the PulldownMenuFreeAll() function.  Here is a prototype:
  13813.  
  13814.              int PulldownMenuFreeAll(PULLDOWN_MENU_PTR pull)
  13815.  
  13816.  
  13817.  
  13818.  
  13819.  
  13820.  
  13821.  
  13822.  
  13823.  
  13824.  
  13825.  
  13826.  
  13827.  
  13828.  
  13829.  
  13830.  
  13831.  
  13832.  
  13833.  
  13834.  
  13835.  
  13836.  
  13837.  
  13838.  
  13839.  Page 236                     The C Window Library                    Page 236
  13840.  
  13841.                            SUMMARY OF PULLDOWN MENUS
  13842.                            -------------------------
  13843.  
  13844.   A pulldown menu is:
  13845.  
  13846.     1)  Made up of a bar menu and popup menus.
  13847.  
  13848.  
  13849.     2)  Consists of two levels, namely the bar menu level and the popup menu
  13850.         level.
  13851.  
  13852.  
  13853.     3)  The bar menu level uses the bar menu key definitions, while the popup
  13854.         menu level uses the popup menu key definitions.
  13855.  
  13856.     4)  The popup menus are initialized by using an array of POPUP_MENU_PTR's.
  13857.         The order of where the popup menus are defined in this array
  13858.         corresponds to each of the bar menu options.
  13859.  
  13860.     5)  A bar menu option may or may not have a popup menu defined for it.
  13861.  
  13862.     6)  When initializing a pulldown menu, you can allow the menu manager to
  13863.         position the popup windows under the bar menu, or you can specify your
  13864.         own positions on the screen for the popup menu windows.
  13865.  
  13866.     7)  When the menu manager calls the user written function the
  13867.         PULLDOWN_MENU_PTR, BAR_MENU_PTR, POPUP_MENU_PTR, the number of the bar
  13868.         entry selected, and the number of the popup selection are passed to
  13869.         the user function.  If there is no popup menu, the POPUP_MENU_PTR
  13870.         passed is a null, and the popup selection number is 0.
  13871.  
  13872.     8)  You can open a pulldown menu from the bar level, or from the pull down
  13873.         level by calling PulldownSelectMenu().
  13874.  
  13875.     9)  You can close a pulldown menu in two ways:  by just disposing of the
  13876.         PULLDOWN_MENU_PTR by calling PulldownMenuFree(), or disposing of all
  13877.         menus used to create the pulldown menu by calling PulldownMenuFreeAll().
  13878.  
  13879.  
  13880.  
  13881.  
  13882.  
  13883.  
  13884.  
  13885.  
  13886.  
  13887.  
  13888.  
  13889.  
  13890.  
  13891.  
  13892.  
  13893.  
  13894.  
  13895.  Page 237                     The C Window Library                    Page 237
  13896.  
  13897.                         EXAMPLE OF PULLDOWN MENU SYSTEM
  13898.                         -------------------------------
  13899.  
  13900.   Here is an example of a pulldown menu system.  This program emulates the
  13901.   Turbo C integrated environment.
  13902.  
  13903.  
  13904.   #include "menu.h"
  13905.  
  13906.   #define BLACKONWHITE   CREATE_VIDEO_ATTRIBUTE(white,black)
  13907.  
  13908.  
  13909.   int menu_routine();
  13910.  
  13911.   POPUP_MENU_ENTRY menu_items1[] = {
  13912.                                     " Load      F3",1,'L',F3,menu_routine,
  13913.                                     " Pick  Alt-F3",2, 'P',ALTF3,menu_routine,
  13914.                                     " New"         ,3, 'N',0,menu_routine,
  13915.                                     " Save      F2",4, 'S',F2,menu_routine,
  13916.                                     " Write to    ",5, 'W',0,menu_routine,
  13917.                                     " Directory   ",6, 'D',0,menu_routine,
  13918.                                     " Change Dir"  ,7, 'C',0,menu_routine,
  13919.                                     " OS shell"    ,8, 'O',0,menu_routine,
  13920.                                     " Quit  Alt-X"  ,9,'Q',ALTX,menu_routine,
  13921.                                     CWL_NULL,0};
  13922.  
  13923.  
  13924.  
  13925.   POPUP_MENU_ENTRY menu_items3[] = {
  13926.                         " Run             Ctrl-F9 ",1,'R',CTRLF9,menu_routine,
  13927.                         " Program reset   Ctrl-F2 ",2,'P',CTRLF2,menu_routine,
  13928.                         " Go to Cursor         F4 ",3,'G',F4,menu_routine,
  13929.                         " Trace into           F7 ",4,'T',F7,menu_routine,
  13930.                         " Step over            F8 ",5,'S',F8,menu_routine,
  13931.                         " User screen      Alt-F5 ",6,'U',ALTF5,menu_routine,
  13932.                         CWL_NULL,0};
  13933.  
  13934.  
  13935.   POPUP_MENU_ENTRY menu_items4[] = {
  13936.           " Compile to OBJ                   ",1,'C',0,menu_routine,
  13937.           " Make EXE file                    ",2,'M',0,menu_routine,
  13938.           " Link EXE file                    ",3,'L',0,menu_routine,
  13939.           " Build all                        ",4,'B',0,menu_routine,
  13940.           " Primary C file:                  ",5,'P',0,menu_routine,
  13941.           " Get info                         ",6,'G',0,menu_routine,
  13942.             CWL_NULL,0};
  13943.  
  13944.  
  13945.  
  13946.  
  13947.  
  13948.  
  13949.  
  13950.  
  13951.  Page 238                     The C Window Library                    Page 238
  13952.  
  13953.   POPUP_MENU_ENTRY menu_items5[] = {
  13954.           " Project Name                     ",1,'P',0,menu_routine,
  13955.           " Break make on                    ",2,'B',0,menu_routine,
  13956.           " Auto dependencies                ",3,'A',0,menu_routine,
  13957.           " Clear project                    ",4,'C',0,menu_routine,
  13958.           " Remove messages                  ",5,'R',0,menu_routine,
  13959.             CWL_NULL,0};
  13960.  
  13961.  
  13962.   POPUP_MENU_ENTRY menu_items6[] = {
  13963.           " Compiler          ",1,'C',0,menu_routine,
  13964.           " Linker            ",2,'L',0,menu_routine,
  13965.           " Environment       ",3,'E',0,menu_routine,
  13966.           " Directories       ",4,'D',0,menu_routine,
  13967.           " Arguments         ",5,'A',0,menu_routine,
  13968.           " Save Options      ",6,'S',0,menu_routine,
  13969.           " Retrieve options  ",7,'R',0,menu_routine,
  13970.           CWL_NULL,0};
  13971.  
  13972.  
  13973.   POPUP_MENU_ENTRY menu_items7[] = {
  13974.           " Evaluate    Ctrl-F4           ",1,'E',CTRLF4,menu_routine,
  13975.           " Call Stack  Ctrl-F3           ",2,'C',CTRLF3,menu_routine,
  13976.           " Find Function                 ",3,'F',0,menu_routine,
  13977.           " Refresh display               ",4,'R',0,menu_routine,
  13978.           " Display swapping     Smart    ",5,'D',0,menu_routine,
  13979.           " Source debugging              ",6,'S',0,menu_routine,
  13980.           CWL_NULL,0};
  13981.  
  13982.  
  13983.   POPUP_MENU_ENTRY menu_items8[] = {
  13984.           " Add watch           Ctrl-F7 ",1,'A',CTRLF7,menu_routine,
  13985.           " Delete watch                ",2,'D',0,menu_routine,
  13986.           " Edit Watch                  ",3,'E',0,menu_routine,
  13987.           " Remove all watches          ",4,'R',0,menu_routine,
  13988.           " Toggle breakpoint   Ctrl-F8 ",6,'T',CTRLF8,menu_routine,
  13989.           " Clear all breakpoints       ",7,'C',0,menu_routine,
  13990.           " View next breakpoint        ",8,'V',0,menu_routine,
  13991.           CWL_NULL,0};
  13992.  
  13993.  
  13994.   BAR_MENU_ENTRY bar_items[] = {
  13995.               "File",1,4,'F',0,NULLFN,
  13996.               "Edit",1,10,'E',0,menu_routine,
  13997.               "Run",1,17,'R',0,NULLFN,
  13998.               "Compile",1,23,'C',0,NULLFN,
  13999.               "Project",1,33,'P',0,NULLFN,
  14000.               "Options", 1,43,'O',0,NULLFN,
  14001.               "Debug",1,53,'D',0,NULLFN,
  14002.               "Break/watch",1,61,'B',0,NULLFN,
  14003.                                     CWL_NULL};
  14004.  
  14005.  
  14006.  
  14007.  Page 239                     The C Window Library                    Page 239
  14008.  
  14009.   POPUP_MENU_ENTRY  *pentry[] = {menu_items1, POPUP_NULL_ENTRY,
  14010.                                  menu_items3,
  14011.                                  menu_items4, menu_items5, menu_items6,
  14012.                                  menu_items7, menu_items8};
  14013.  
  14014.   unsigned menu_colors[5];    /* Menu colors */
  14015.   BAR_MENU_PTR bar;           /* Pointer to bar menu */
  14016.   POPUP_MENU_PTR popups[8];   /* Array of pointers to popup menus */
  14017.   PULLDOWN_MENU_PTR pull;     /* Pointer to pulldown menu */
  14018.  
  14019.   WPOINTER my_open();         /* Pointer to custom bar window open function */
  14020.   unsigned int popuprank[] = {1,1,1,1,1,1,1,1};  /* Ranks of popup windows */
  14021.   int popupstart[] = {1,1,1,1,1,1,1,1}; /* Starting option for each popup
  14022.                                            menu */
  14023.   int height[] = {9,0,6,6,5,7,6,8};     /* height of each window */
  14024.  
  14025.   WPOINTER pw;  /* Misc. windows, not part of menu
  14026.                                             system */
  14027.  
  14028.   char *line =
  14029.           "─────────────────────────────"; /* Horizontal line */
  14030.  
  14031.  
  14032.   main()
  14033.   {
  14034.     int i;
  14035.     WindowInitializeSystem();
  14036.     WindowSaveInitial(0);
  14037.     pw = WindowInitialize(BORDER,5,10,70,5,BLACKONWHITE,BLACKONWHITE,
  14038.                           SINGLEBOX);
  14039.     WindowOpen(pw);
  14040.    /* define colors */
  14041.     menu_colors[0] = CREATE_VIDEO_ATTRIBUTE(white,black);
  14042.     menu_colors[1] = CREATE_VIDEO_ATTRIBUTE(white,black);
  14043.     menu_colors[2] = CREATE_VIDEO_ATTRIBUTE(white,blue);
  14044.     menu_colors[3] = CREATE_VIDEO_ATTRIBUTE(cyan,black);
  14045.     menu_colors[4] = CREATE_VIDEO_ATTRIBUTE(white,black);
  14046.  
  14047.     bar = BarCreateMenu(bar_items,  /* Array of BAR_MENU_ENTRY's   */
  14048.                         menu_colors,/* Pointer to menu colors      */
  14049.                         6,          /* Row to open bar menu window */
  14050.                         1,          /* Column to open bar menu window */
  14051.                         BARWRAP | BARSTATIC,
  14052.                         my_open);   /* Customized window open function */
  14053.  
  14054.                  /* Now loop to create all popup menus
  14055.           Be careful and assign NULL to the second popup menu */
  14056.  
  14057.  
  14058.  
  14059.  
  14060.  
  14061.  
  14062.  
  14063.  Page 240                     The C Window Library                    Page 240
  14064.  
  14065.     for (i=0; i<8; i++)       /* Loop for all popup menus */
  14066.     {
  14067.       if (pentry[i] != POPUP_NULL_ENTRY)  /* Skip over NULL popup entry */
  14068.       {
  14069.         popups[i] =
  14070.         PopupCreateMenu(pentry[i],   /* Array of POPUP_MENU_ENTRY's */
  14071.                         menu_colors, /* Array of menu colors,        */
  14072.  
  14073.                           /* The next two arguments will later be ignored */
  14074.                           1,           /* Row to open popup window on */
  14075.                           1,           /* Column to open popup */
  14076.                           height[i], /* height of the popup window   */
  14077.                                            /* No custom window open
  14078.                                               functions */
  14079.                           POPUPWRAP | POPUPSTATIC,  /* wrap the window */
  14080.                           WNULLFN,
  14081.                           VWNULLFN);
  14082.  
  14083.               /* Now set the popup menu options */
  14084.       }
  14085.       else
  14086.         popups[i] = (POPUP_MENU_PTR)0;  /* Make this a null POPUP_MENU_PTR */
  14087.     }  /* end for (i=0 ... */
  14088.  
  14089.     VirtualWriteString(POPUP_VIRTUAL_WINDOW(popups[7]),line,5,1);
  14090.     PopupMakeEntryUnavailable(popups[6],2);   /* hide 2nd and 3rd entries in */
  14091.     PopupMakeEntryUnavailable(popups[6],3);   /* popups[6]  */
  14092.     PopupSetOptions(popups[6],POPUPOVERRIDE,1);
  14093.  
  14094.     pull = PulldownCreateMenu(popups,bar,1);
  14095.     PulldownSelectMenu(pull,1,1,popuprank,popupstart,1);
  14096.     PulldownMenuFree(pull);
  14097.   }
  14098.  
  14099.   int menu_routine(PULLDOWN_MENU_PTR p, BAR_MENU_PTR b,
  14100.                    POPUP_MENU_PTR pop,
  14101.                    unsigned int hs, unsigned int vs)
  14102.   {
  14103.     int ch;
  14104.     WindowClear(pw);
  14105.     WindowPrintf(pw,
  14106.              "You have selected bar option %s\npopup option %s\n",
  14107.               BAR_ENTRY_STRING(b,hs),POPUP_ENTRY_STRING(pop,vs));
  14108.     WindowWriteCenterString(pw,"Press Escape to Quit",3);
  14109.     WindowWriteCenterString(pw,"Press any other key to continue...",4);
  14110.     WindowDisplay(pw,1,NOEFFECT);
  14111.     ch = GET_KEY();
  14112.     WindowHide(pw,NOEFFECT);
  14113.     if (ch == ESC)
  14114.       return PULLDOWN_EXIT;
  14115.     return PULLDOWN_CONTINUE;
  14116.   }
  14117.  
  14118.  
  14119.  Page 241                     The C Window Library                    Page 241
  14120.  
  14121.   WPOINTER my_open()          /* Custom window open function for bar menu */
  14122.   {
  14123.     WPOINTER w;
  14124.     w = WindowInitialize(NOBORDER,1,1,80,1,BLACKONWHITE,BLACKONWHITE,"");
  14125.     WindowOpen(w);
  14126.     return w;
  14127.   }
  14128.  
  14129.  
  14130.  
  14131.  
  14132.  
  14133.  
  14134.  
  14135.  
  14136.  
  14137.  
  14138.  
  14139.  
  14140.  
  14141.  
  14142.  
  14143.  
  14144.  
  14145.  
  14146.  
  14147.  
  14148.  
  14149.  
  14150.  
  14151.  
  14152.  
  14153.  
  14154.  
  14155.  
  14156.  
  14157.  
  14158.  
  14159.  
  14160.  
  14161.  
  14162.  
  14163.  
  14164.  
  14165.  
  14166.  
  14167.  
  14168.  
  14169.  
  14170.  
  14171.  
  14172.  
  14173.  
  14174.  
  14175.  Page 242                     The C Window Library                    Page 242
  14176.  
  14177.                            MISCELLANEOUS FUNCTIONS
  14178.                            -----------------------
  14179.  
  14180.   There are other functions in The C Window Library that you can use without
  14181.   defining windows.
  14182.  
  14183.  
  14184.  
  14185.                        SETTING AND CHECKING VIDEO PAGES
  14186.                        --------------------------------
  14187.  
  14188.   The following functions sets and checks video pages.  Your video setup must
  14189.   support multiple video pages for the examples given in this section to work.
  14190.   Please refer to page 5 for a discussion of video adapters and the number
  14191.   of pages each will support.
  14192.  
  14193.  
  14194.  
  14195.   CheckVideoPage()
  14196.   ----------------
  14197.  
  14198.   This function checks to see if the video page is valid.  Here is the
  14199.   prototype:
  14200.  
  14201.  
  14202.                  int CheckVideoPage(int page)
  14203.  
  14204.   If page is valid, CheckVideoPage() returns NO_ERROR.  If it is not, the return
  14205.   value is INVALID_PAGE.
  14206.  
  14207.  
  14208.   Example:
  14209.  
  14210.  
  14211.   #include "window.h"
  14212.  
  14213.   main()
  14214.   {
  14215.     int i;
  14216.     WindowInitializeSystem();
  14217.     for (i=0;i<8;i++)
  14218.     {
  14219.       if (CheckVideoPage(i) == NO_ERROR)
  14220.         printf("\nValid video page #%d",i);
  14221.       else
  14222.         printf("\nInvalid video page #%d",i);
  14223.     }
  14224.   }
  14225.  
  14226.  
  14227.  
  14228.  
  14229.  
  14230.  
  14231.  
  14232.  Page 243                     The C Window Library                    Page 243
  14233.  
  14234.   SetActiveVideoPage() function
  14235.   -----------------------------
  14236.  
  14237.   The SetActiveVideoPage() function sets the active video page.  Here is a
  14238.   prototype:
  14239.  
  14240.            int SetActiveVideoPage(int page)
  14241.  
  14242.   Any windows initialized with WindowInitialize() will have its output directed
  14243.   to the current active video page on initialization.  This function DOES NOT
  14244.   change the visible display page.
  14245.  
  14246.   Example:
  14247.  
  14248.   #include "window.h"
  14249.   #define NORM CREATE_VIDEO_ATTRIBUTE(black,white)
  14250.  
  14251.   WPOINTER w1, w2;
  14252.   main()
  14253.   {
  14254.     WindowInitializeSystem();
  14255.  
  14256.     /* Save Base Screen for video pages 0 and 1 */
  14257.     WindowSaveInitial(0);
  14258.     WindowSaveInitial(1);
  14259.  
  14260.     /* Set the active video page */
  14261.     SetActiveVideoPage(0);
  14262.     w1 = WindowInitialize(BORDER,1,1,10,10,NORM,NORM,SINGLEBOX);
  14263.     SetActiveVideoPage(1);
  14264.     w2 = WindowInitialize(BORDER,1,1,10,10,NORM,NORM,SINGLEBOX);
  14265.   }
  14266.  
  14267.   The above example shows two windows, w1 and w2, being open on different video
  14268.   pages.  Please note the two calls to WindowSaveInitial().  The first saves
  14269.   the base screen on video page 0, and the second call saves the initial screen
  14270.   on page 1.  The first call to SetActiveVideoPage() sets the active video page
  14271.   to page 0.  This is usually the active video page on startup.  Since the
  14272.   active page is 0, w1 is opened with page 0 as its video page.  The second
  14273.   call to SetActiveVideoPage() makes page 1 the active page, therefore w2 is
  14274.   initialized to send its output to video page 1.
  14275.  
  14276.   If there are no errors, SetActiveVideoPage() returns NO_ERROR.
  14277.  
  14278.   If there are errors, SetActiveVideoPage() returns INVALID_PAGE if the video
  14279.   page is invalid.
  14280.  
  14281.  
  14282.  
  14283.  
  14284.  
  14285.  
  14286.  
  14287.  
  14288.  Page 244                     The C Window Library                    Page 244
  14289.  
  14290.   SetVisibleVideoPage() function
  14291.   ------------------------------
  14292.  
  14293.   The SetVisibleVideoPage() function sets the visible video page.  Here is a
  14294.   prototype:
  14295.  
  14296.            int SetVisibleVideoPage(int page)
  14297.  
  14298.   The visible video page is the page displayed on the screen.
  14299.  
  14300.  
  14301.   Example:
  14302.  
  14303.   #include "window.h"
  14304.   #define NORM CREATE_VIDEO_ATTRIBUTE(black,white)
  14305.  
  14306.   WPOINTER w1,w2;
  14307.  
  14308.   main()
  14309.   {
  14310.     WindowInitializeSystem();
  14311.  
  14312.     /* Make sure video page is 0 */
  14313.     SetVisibleVideoPage(0);
  14314.     SetActiveVideoPage(0);
  14315.  
  14316.     /*Save Base screen for video pages 0 and 1 */
  14317.     WindowSaveInitial(0);
  14318.     WindowSaveInitial(1);
  14319.  
  14320.     /* Initialize Windows */
  14321.     w1 = WindowInitialize(BORDER,1,1,30,10,NORM,NORM,SINGLEBOX);
  14322.     SetActiveVideoPage(1);
  14323.     w2 = WindowInitialize(BORDER,1,1,30,10,NORM,NORM,SINGLEBOX);
  14324.     WindowOpen(w1);
  14325.     WindowOpen(w2);
  14326.     WindowWriteString(w1,"This is window 1 on page 0",1,1);
  14327.     WindowWriteString(w2,"This is window 2 on page 1",1,1);
  14328.  
  14329.     /* Display video page 0 */
  14330.     WindowDisplay(w1,1,NOEFFECT);
  14331.     GET_KEY();
  14332.  
  14333.     /* Change to video page 1 and display */
  14334.     SetVisibleVideoPage(1);
  14335.     WindowDisplay(w2,1,NOEFFECT);
  14336.     GET_KEY();
  14337.  
  14338.     /* Reset to page 0 */
  14339.     SetVisibleVideoPage(0);
  14340.   }
  14341.  
  14342.  
  14343.  
  14344.  Page 245                     The C Window Library                    Page 245
  14345.  
  14346.   The example above initializes two windows.  w1 is initialized on page 0 and
  14347.   w2 is initialized on page 1.  Also note that there are two calls to
  14348.   WindowSaveInitial(), one for page 0 and another for page 1.  The first window
  14349.   displayed is w1.  Once a key is pressed the visible page is switched to page
  14350.   1 by calling SetVisibleVideoPage().  The last line of the program sets the
  14351.   visible page back to page 0.  You should do this on exit of any program that
  14352.   changes video pages.
  14353.  
  14354.   If there are no errors, SetVisibleVideoPage() returns NO_ERROR.
  14355.  
  14356.   If there are errors, SetVisibleVideoPage() returns INVALID_PAGE if the video
  14357.   page is invalid.
  14358.  
  14359.  
  14360.  
  14361.  
  14362.  
  14363.  
  14364.  
  14365.  
  14366.  
  14367.  
  14368.  
  14369.  
  14370.  
  14371.  
  14372.  
  14373.  
  14374.  
  14375.  
  14376.  
  14377.  
  14378.  
  14379.  
  14380.  
  14381.  
  14382.  
  14383.  
  14384.  
  14385.  
  14386.  
  14387.  
  14388.  
  14389.  
  14390.  
  14391.  
  14392.  
  14393.  
  14394.  
  14395.  
  14396.  
  14397.  
  14398.  
  14399.  
  14400.  Page 246                     The C Window Library                    Page 246
  14401.  
  14402.                        GENERAL STRING WRITING FUNCTIONS
  14403.                        --------------------------------
  14404.  
  14405.   The following functions write strings to the active video page.  These
  14406.   functions are not window functions, therefore you should use these functions
  14407.   when you are not using windows created with The C Window Library unless you
  14408.   are careful in using them.  The advantage of using these functions instead of
  14409.   the normal string writing functions found in most C compiler libraries (i.e.
  14410.   printf(), puts(), etc.) is that the output is written directly to screen
  14411.   memory, which results in fast output.  If the BIOS option is selected, BIOS
  14412.   functions are used to write the strings.  Refer to page 4 for a discussion of
  14413.   direct screen writing and BIOS functions.
  14414.  
  14415.  
  14416.  
  14417.  
  14418.   VideoWriteString()
  14419.   ------------------
  14420.  
  14421.   This function writes a null terminated string to the active video page.  Here
  14422.   is the prototype:
  14423.  
  14424.             void VideoWriteString(char *string, int row, int col)
  14425.  
  14426.   The first argument is the string, and the second and third arguments are the
  14427.   (row,col) position of the active video page to place the string.  There is no
  14428.   check to see if (row,col) is out of bounds.  The attribute that is used is
  14429.   determined by the current video attribute at each character position on the
  14430.   screen.
  14431.  
  14432.  
  14433.   Example:
  14434.  
  14435.  
  14436.   #include "window.h"
  14437.  
  14438.   main()
  14439.   {
  14440.     int i;
  14441.     WindowInitializeSystem();
  14442.     for (i=1;i<=10;i++)
  14443.       VideoWriteString("Hello, World",i,1);
  14444.   }
  14445.  
  14446.  
  14447.   There is no return value for VideoWriteString().
  14448.  
  14449.  
  14450.  
  14451.  
  14452.  
  14453.  
  14454.  
  14455.  
  14456.  Page 247                     The C Window Library                    Page 247
  14457.  
  14458.   VideoWriteStringAttr()
  14459.   ----------------------
  14460.  
  14461.   This function writes a null terminated string to the active video page using
  14462.   a video attribute.  Here is the prototype:
  14463.  
  14464.        void VideoWriteStringAttr(char *string, int row, int col, int attr)
  14465.  
  14466.   The first argument is the string, the second and third arguments are the
  14467.   (row,col) position of the active video page to place the string, and the
  14468.   last argument is the video attribute to use.  There is no check to see if
  14469.   (row,col) is out of bounds.  The last argument is the video attribute to use.
  14470.  
  14471.  
  14472.   Example:
  14473.  
  14474.  
  14475.   #include "window.h"
  14476.   #define REVERSE  CREATE_VIDEO_ATTRIBUTE(white,black)
  14477.  
  14478.   main()
  14479.   {
  14480.     int i;
  14481.     WindowInitializeSystem();
  14482.     for (i=1;i<=10;i++)
  14483.       VideoWriteStringAttr("Hello, World",i,1,REVERSE);
  14484.   }
  14485.  
  14486.  
  14487.   There is no return value for VideoWriteStringAttr().
  14488.  
  14489.  
  14490.  
  14491.  
  14492.  
  14493.   VideoWriteAttributes()
  14494.   ----------------------
  14495.  
  14496.   This function writes a string of attributes to the active video page.
  14497.   Here is the prototype:
  14498.  
  14499.      void VideoWriteAttributes(char *buffer, int row, int col, int num)
  14500.  
  14501.   The first argument is the buffer that contains the video attributes.  The
  14502.   second and third arguments are the (row,col) position of the active video
  14503.   page to place the attributes, and the last arguments is the number of
  14504.   attributes to write from the buffer.  There is no check to see if (row,col)
  14505.   is out of bounds, or if num attributes will exceed the right edge of the
  14506.   screen.
  14507.  
  14508.  
  14509.  
  14510.  
  14511.  
  14512.  Page 248                     The C Window Library                    Page 248
  14513.  
  14514.   Example:
  14515.  
  14516.  
  14517.   #include "window.h"
  14518.   #include <string.h>
  14519.   #define REVERSE  CREATE_VIDEO_ATTRIBUTE(white,black)
  14520.   char buf[12];
  14521.  
  14522.   main()
  14523.   {
  14524.     WindowInitializeSystem();
  14525.     VideoWriteString("Hello, World",1,1);
  14526.     GET_KEY();
  14527.     memset(buf,REVERSE,sizeof(buf));
  14528.     VideoWriteAttributes(buf,1,1,sizeof(buf));
  14529.   }
  14530.  
  14531.   The example above writes a string using the VideoWriteString() function and
  14532.   then changes the attribute of the string by setting a buffer to the REVERSE
  14533.   attribute and using the VideoWriteAttributes() function with this buffer.
  14534.  
  14535.   There is no return value for VideoWriteAttributes().
  14536.  
  14537.  
  14538.  
  14539.   VideoWriteCenterString()
  14540.   ------------------------
  14541.  
  14542.   The VideoWriteCenterString() function centers a string at a certain row of
  14543.   the active video page.  Here is the prototype:
  14544.  
  14545.              void VideoWriteCenterString(char *string, int row)
  14546.  
  14547.   The first argument is the string and the second argument is the row to write
  14548.   on the active video page to write the string.   There is no check to see if
  14549.   row is out of bounds.
  14550.  
  14551.  
  14552.   Example:
  14553.  
  14554.  
  14555.   #include "window.h"
  14556.  
  14557.   main()
  14558.   {
  14559.     int i;
  14560.     WindowInitializeSystem();
  14561.     for (i=1;i<=10;i++)
  14562.       VideoWriteCenterString("Hello, World",i);
  14563.   }
  14564.  
  14565.  
  14566.   There is no return value for VideoWriteCenterString().
  14567.  
  14568.  Page 249                     The C Window Library                    Page 249
  14569.  
  14570.   VideoWriteCenterStringAttr()
  14571.   ----------------------------
  14572.  
  14573.   The VideoWriteCenterStringAttr() function centers a string at a certain row
  14574.   of the active video page with a specified video attribute.  Here is the
  14575.   prototype:
  14576.  
  14577.           void VideoWriteCenterStringAttr(char *string, int row, int attr)
  14578.  
  14579.   The first argument is the string and the second argument is the row to write
  14580.   on the active video page to write the string.  The third argument is the
  14581.   video attribute to use.   There is no check to see if row is out of bounds.
  14582.  
  14583.  
  14584.   Example:
  14585.  
  14586.  
  14587.   #include "window.h"
  14588.   #define REVERSE CREATE_VIDEO_ATTRIBUTE(white,black)
  14589.  
  14590.   main()
  14591.   {
  14592.     int i;
  14593.     WindowInitializeSystem();
  14594.     for (i=1;i<=10;i++)
  14595.       VideoWriteCenterStringAttr("Hello, World",i,REVERSE);
  14596.   }
  14597.  
  14598.   There is no return value for VideoWriteCenterStringAttr().
  14599.  
  14600.  
  14601.  
  14602.  
  14603.   VideoWriteCharAndAttr()
  14604.   -----------------------
  14605.  
  14606.   The VideoWriteCharAndAttr() function writes a string of character-attribute
  14607.   pairs to the active video page.  Here is the prototype:
  14608.  
  14609.       void VideoWriteCharAndAttr(char *buffer, int row, int col, int num)
  14610.  
  14611.   The first argument is the buffer that holds the character attribute pairs.
  14612.   This buffer should be in the following form:
  14613.  
  14614.        -----------------------------------------------
  14615.        |char1 | attr1 | char2 | attr2 | char3 | attr3| ...
  14616.        -----------------------------------------------
  14617.  
  14618.   The second and third arguments are the (row,col) position of the active video
  14619.   page to write the string.  The last argument is the number of
  14620.   character-attribute pairs to write.
  14621.  
  14622.  
  14623.  
  14624.  Page 250                     The C Window Library                    Page 250
  14625.  
  14626.   Example:
  14627.  
  14628.   #include "window.h"
  14629.   #define REVERSE CREATE_VIDEO_ATTRIBUTE(white,black)
  14630.   char buf[24];
  14631.  
  14632.   main()
  14633.   {
  14634.     int i,j;
  14635.     WindowInitializeSystem();
  14636.     for (i=0,j='A'; i<24; i+=2,j++)
  14637.     {
  14638.       buf[i] = j;
  14639.       buf[i+1] = REVERSE;
  14640.     }
  14641.     for (i=1;i<=10;i++)
  14642.       VideoWriteCharAndAttr(buf,i,1,12);
  14643.   }
  14644.  
  14645.   The example above creates a string of character attribute pairs and then
  14646.   writes this string using the VideoWriteCharAndAttr() function.
  14647.  
  14648.   There is no return value for VideoWriteCharAndAttr().
  14649.  
  14650.  
  14651.   VideoWriteStringCC()
  14652.   --------------------
  14653.  
  14654.   This function writes a string centered around a column on the active video
  14655.   page.  Here is the prototype:
  14656.  
  14657.           void VideoWriteStringCC(char *string, int row, int col)
  14658.  
  14659.   The first argument is the string.  The second argument is the row, and the
  14660.   third argument is the column to center the string around.
  14661.  
  14662.   Example:
  14663.  
  14664.   #include "window.h"
  14665.  
  14666.   main()
  14667.   {
  14668.     int i;
  14669.     WindowInitializeSystem();
  14670.     VideoWriteStringCC("This",1,10);
  14671.     VideoWriteStringCC("is",2,10);
  14672.     VideoWriteStringCC("centered",3,10);
  14673.     VideoWriteStringCC("around",4,10);
  14674.     VideoWriteStringCC("column",5,10);
  14675.     VideoWriteStringCC("10",6,10);
  14676.   }
  14677.  
  14678.   There is no return value for VideoWriteStringCC().
  14679.  
  14680.  Page 251                     The C Window Library                    Page 251
  14681.  
  14682.   VideoWriteStringCCAttr()
  14683.   ------------------------
  14684.  
  14685.   This function writes a string centered around a column on the active video
  14686.   page with a specified video attribute.  Here is the prototype:
  14687.  
  14688.       void VideoWriteStringCCAttr(char *string, int row, int col, int attr)
  14689.  
  14690.   The first argument is the string.  The second argument is the row.  The third
  14691.   argument is the column to center the string around, and the fourth argument
  14692.   is the attribute to use.
  14693.  
  14694.  
  14695.   Example:
  14696.  
  14697.   #include "window.h"
  14698.   #define REVERSE CREATE_VIDEO_ATTRIBUTE(white,black)
  14699.   main()
  14700.   {
  14701.     int i;
  14702.     WindowInitializeSystem();
  14703.     VideoWriteStringCCAttr("This",1,10,REVERSE);
  14704.     VideoWriteStringCCAttr("is",2,10,REVERSE);
  14705.     VideoWriteStringCCAttr("centered",3,10,REVERSE);
  14706.     VideoWriteStringCCAttr("around",4,10,REVERSE);
  14707.     VideoWriteStringCCAttr("column",5,10,REVERSE);
  14708.     VideoWriteStringCCAttr("10",6,10,REVERSE);
  14709.   }
  14710.  
  14711.   There is no return value for VideoWriteStringCCAttr().
  14712.  
  14713.  
  14714.  
  14715.  
  14716.   VideoWriteStringRJ()
  14717.   --------------------
  14718.  
  14719.   The VideoWriteStringRJ() function writes a string to the screen that is right
  14720.   justified at column col.  If the string will not fit within column 1, the
  14721.   string is still right justified, but excess characters to the left of column
  14722.   1 are clipped.  This function writes a string  column on the active video
  14723.   page.  Here is the prototype:
  14724.  
  14725.           void VideoWriteStringRJ(char *string, int row, int col)
  14726.  
  14727.   The first argument is the string.  The second argument is the row, and the
  14728.   third argument is the column to right justify the string on.
  14729.  
  14730.  
  14731.  
  14732.  
  14733.  
  14734.  
  14735.  
  14736.  Page 252                     The C Window Library                    Page 252
  14737.  
  14738.   Example:
  14739.  
  14740.   #include "window.h"
  14741.   main()
  14742.   {
  14743.     int i;
  14744.     WindowInitializeSystem();
  14745.     VideoWriteStringRJ("This",1,10);
  14746.     VideoWriteStringRJ("is",2,10);
  14747.     VideoWriteStringRJ("right",3,10);
  14748.     VideoWriteStringRJ("justified",4,10);
  14749.     VideoWriteStringRJ("on ",5,10);
  14750.     VideoWriteStringRJ("column",6,10);
  14751.     VideoWriteStringRJ("10",7,10);
  14752.   }
  14753.  
  14754.   There is no return value for VideoWriteStringRJ().
  14755.  
  14756.  
  14757.  
  14758.   VideoWriteStringRJAttr()
  14759.   ------------------------
  14760.  
  14761.   The VideoWriteStringRJAttr() function writes a string to the screen that is
  14762.   right justified at column col with a specified video attribute.  If the
  14763.   string will not fit within column 1, the string is still right justified, but
  14764.   excess characters to the left of column 1 are clipped.  This function writes
  14765.   a string  column on the active video page.  Here is the prototype:
  14766.  
  14767.       void VideoWriteStringRJAttr(char *string, int row, int col, int attr)
  14768.  
  14769.   The first argument is the string.  The second argument is the row.  The third
  14770.   argument is the column to right justify the string on, and the last argument
  14771.   is the video attribute to use.
  14772.  
  14773.   Example:
  14774.  
  14775.   #include "window.h"
  14776.   #define REVERSE  CREATE_VIDEO_ATTRIBUTE(white,black)
  14777.   main()
  14778.   {
  14779.     int i;
  14780.     WindowInitializeSystem();
  14781.     VideoWriteStringRJAttr("This",1,10,REVERSE);
  14782.     VideoWriteStringRJAttr("is",2,10,REVERSE);
  14783.     VideoWriteStringRJAttr("right",3,10,REVERSE);
  14784.     VideoWriteStringRJAttr("justified",4,10,REVERSE);
  14785.     VideoWriteStringRJAttr("on ",5,10,REVERSE);
  14786.     VideoWriteStringRJAttr("column",6,10,REVERSE);
  14787.     VideoWriteStringRJAttr("10",7,10,REVERSE);
  14788.   }
  14789.  
  14790.   There is no return value for VideoWriteStringRJAttr().
  14791.  
  14792.  Page 253                     The C Window Library                    Page 253
  14793.  
  14794.   VideoPrintf()
  14795.   -------------
  14796.  
  14797.   The VideoPrintf() function writes formatted strings to the active video page.
  14798.   This function works exactly the same as printf() except that output is
  14799.   written directly to the screen.  Here is the prototype:
  14800.  
  14801.                 void VideoPrintf(char *format [,arg1,arg2...])
  14802.  
  14803.   The location of the output is placed at the current cursor position.  The
  14804.   cursor is advanced to one character beyond the last character of output.
  14805.  
  14806.   Example:
  14807.  
  14808.   #include "window.h"
  14809.   int i = 3;
  14810.   double j = 5.6;
  14811.   main()
  14812.   {
  14813.     WindowInitializeSystem();
  14814.     VideoPrintf("3+2 is equal to %d\n",3+2);
  14815.     VideoPrintf("i is equal to %d\nj is equal to %lf\n",i,j);
  14816.   }
  14817.  
  14818.   Unlike printf(), there is no return value with VideoPrintf().
  14819.  
  14820.  
  14821.  
  14822.   VideoPrintfAttr()
  14823.   -----------------
  14824.  
  14825.   The VideoPrintfAttr() function works the same as VideoPrintf() except that a
  14826.   video attribute is specified.  Here is the prototype:
  14827.  
  14828.                 void VideoPrintfAttr(int attr, char *format [,arg1,arg2...])
  14829.  
  14830.   The first argument is the attribute to use.  The second argument is the
  14831.   format string, and the other arguments are optional arguments.
  14832.  
  14833.   Example:
  14834.  
  14835.   #include "window.h"
  14836.   #define REVERSE  CREATE_VIDEO_ATTRIBUTE(white,black)
  14837.   int i = 3;
  14838.   double j = 5.6;
  14839.   main()
  14840.   {
  14841.     WindowInitializeSystem();
  14842.     VideoPrintfAttr(REVERSE,"3+2 is equal to %d\n",3+2);
  14843.     VideoPrintfAttr(REVERSE,"i is equal to %d\nj is equal to %lf\n",i,j);
  14844.   }
  14845.  
  14846.   Unlike printf(), there is no return value with VideoPrintfAttr().
  14847.  
  14848.  Page 254                     The C Window Library                    Page 254
  14849.  
  14850.                READING CHARACTERS AND ATTRIBUTES FROM THE SCREEN
  14851.                -------------------------------------------------
  14852.  
  14853.   These functions read characters and/or attributes from the active video page.
  14854.  
  14855.  
  14856.   VideoReadCharacters()
  14857.   ---------------------
  14858.  
  14859.   This function reads characters from the active video page into a buffer.
  14860.   Here is the prototype:
  14861.  
  14862.  
  14863.     void VideoReadCharacters(char *buffer, int row, int col, int num)
  14864.  
  14865.   The first argument is the buffer to store the characters.  The second and
  14866.   third arguments are the (row,col) position on the active video page.  The
  14867.   last argument is the number of characters to read in.  There is no check to
  14868.   see if the row, col, or the num arguments are in bounds of the screen.
  14869.  
  14870.  
  14871.   Example:
  14872.  
  14873.   #include "window.h"
  14874.  
  14875.   char buf[25];
  14876.  
  14877.   main()
  14878.   {
  14879.     WindowInitializeSystem();
  14880.     VideoReadCharacters(buf,1,1,25);
  14881.   }
  14882.  
  14883.  
  14884.   The example above reads the characters on the screen starting at position
  14885.   (1,1).
  14886.  
  14887.   There is no return value for VideoReadCharacters().
  14888.  
  14889.  
  14890.  
  14891.   VideoReadAttributes()
  14892.   ---------------------
  14893.  
  14894.   This function reads attributes from the active video page into a buffer.
  14895.   Here is the prototype:
  14896.  
  14897.     void VideoReadAttributes(char *buffer, int row, int col, int num)
  14898.  
  14899.   The first argument is the buffer to store the attributes.  The second and
  14900.   third arguments are the (row,col) position on the active video page.  The
  14901.   last argument is the number of attributes to read in.  There is no check to
  14902.   see if the row, col, or the num arguments are in bounds of the screen.
  14903.  
  14904.  Page 255                     The C Window Library                    Page 255
  14905.  
  14906.   Example:
  14907.  
  14908.   #include "window.h"
  14909.  
  14910.   char buf[25];
  14911.  
  14912.   main()
  14913.   {
  14914.     WindowInitializeSystem();
  14915.     VideoReadAttributes(buf,1,1,25);
  14916.   }
  14917.  
  14918.  
  14919.   The example above reads the attributes on the screen starting at position
  14920.   (1,1).
  14921.  
  14922.   There is no return value for VideoReadAttributes().
  14923.  
  14924.  
  14925.  
  14926.  
  14927.   VideoReadCharAndAttr()
  14928.   ----------------------
  14929.  
  14930.   This function reads character-attribute pairs from the active video page
  14931.   into a buffer.  Here is the prototype:
  14932.  
  14933.  
  14934.     void VideoReadCharAndAttr(char *buffer, int row, int col, int num)
  14935.  
  14936.   The first argument is the buffer to store the character-attribute pairs.  The
  14937.   second and third arguments are the (row,col) position on the active video
  14938.   page.  The last argument is the number of character-attribute pairs to read
  14939.   in.  There is no check to see if the row, col, or the num arguments are in
  14940.   bounds of the screen.
  14941.  
  14942.   Example:
  14943.  
  14944.   #include "window.h"
  14945.  
  14946.   char buf[26];
  14947.  
  14948.   main()
  14949.   {
  14950.     WindowInitializeSystem();
  14951.     VideoReadCharAndAttr(buf,1,1,13);
  14952.   }
  14953.  
  14954.   The example above reads the character-attribute pairs on the screen starting
  14955.   at position (1,1).
  14956.  
  14957.   There is no return value for VideoReadCharAndAttr().
  14958.  
  14959.  
  14960.  Page 256                     The C Window Library                    Page 256
  14961.  
  14962.                                  DRAWING BOXES
  14963.                                  -------------
  14964.  
  14965.   The following functions draw boxes on the screen.
  14966.  
  14967.  
  14968.   VideoDrawBox()
  14969.   --------------
  14970.  
  14971.   The VideoDrawBox() function draws a box on the screen.  Here is the
  14972.   prototype:
  14973.  
  14974.      void VideoDrawBox(int urow, int ucol, int lrow, int lcol, char *boxchars)
  14975.  
  14976.   The box is defined by a rectangular region.  The urow and ucol arguments are
  14977.   the coordinates of the upper left hand corner of the box.  The lrow and lcol
  14978.   arguments are the coordinates of the lower right hand corner of the box.  The
  14979.   last argument is a string of box drawing characters to use.  You can use the
  14980.   predefined box types in the header file vidsys.h, or you can make your own.
  14981.   Refer to page 11 for more information on box types.
  14982.  
  14983.   There is no check to see if the coordinates are in bounds.
  14984.  
  14985.   Example:
  14986.  
  14987.   #include "window.h"
  14988.  
  14989.   main()
  14990.   {
  14991.     WindowInitializeSystem();
  14992.     ClearScreen(CREATE_VIDEO_ATTRIBUTE(black,white));
  14993.  
  14994.     /* Draw two boxes */
  14995.     VideoDrawBox(1,1,10,10,SINGLEBOX);
  14996.     VideoDrawBox(1,11,10,21,DOUBLEBOX);
  14997.   }
  14998.  
  14999.   There is no return value for VideoDrawBox().
  15000.  
  15001.  
  15002.  
  15003.   VideoDrawBoxAttr()
  15004.   ------------------
  15005.  
  15006.   The VideoDrawBoxAttr() function draws a box on the screen with a specified
  15007.   video attribute.  Here is the prototype:
  15008.  
  15009.   void VideoDrawBoxAttr(int urow, int ucol, int lrow, int lcol, char *boxchars,
  15010.                         int attr)
  15011.  
  15012.   This function works the same way as the VideoDrawBox() function.  Note that
  15013.   the last argument is the video attribute to use.  There is no check to see if
  15014.   the coordinates are in bounds.
  15015.  
  15016.  Page 257                     The C Window Library                    Page 257
  15017.  
  15018.   Example:
  15019.  
  15020.   #include "window.h"
  15021.   #define REVERSE CREATE_VIDEO_ATTRIBUTE(black,white)
  15022.  
  15023.   main()
  15024.   {
  15025.     WindowInitializeSystem();
  15026.     ClearScreen(CREATE_VIDEO_ATTRIBUTE(black,white));
  15027.  
  15028.     /* Draw two boxes */
  15029.     VideoDrawBoxAttr(1,1,10,10,SINGLEBOX,REVERSE);
  15030.     VideoDrawBoxAttr(1,11,10,21,DOUBLEBOX,REVERSE);
  15031.   }
  15032.  
  15033.  
  15034.   There is no return value for VideoDrawBoxAttr().
  15035.  
  15036.  
  15037.  
  15038.  
  15039.  
  15040.  
  15041.  
  15042.  
  15043.  
  15044.  
  15045.  
  15046.  
  15047.  
  15048.  
  15049.  
  15050.  
  15051.  
  15052.  
  15053.  
  15054.  
  15055.  
  15056.  
  15057.  
  15058.  
  15059.  
  15060.  
  15061.  
  15062.  
  15063.  
  15064.  
  15065.  
  15066.  
  15067.  
  15068.  
  15069.  
  15070.  
  15071.  
  15072.  Page 258                     The C Window Library                    Page 258
  15073.  
  15074.                       SAVING AND RESTORING SCREEN IMAGES
  15075.                       ----------------------------------
  15076.  
  15077.   The following functions save rectangular regions of the screen in a buffer,
  15078.   and restore rectangular portions of the screen.  These routines exist in The
  15079.   C Window Library so that advanced C programmers can have general screen
  15080.   saving/restoring routines handy.  As always, you should be careful in using
  15081.   these functions at the same time you are using windows created with The C
  15082.   Window Library.
  15083.  
  15084.  
  15085.  
  15086.   VideoSave()
  15087.   -----------
  15088.  
  15089.   The VideoSave() function saves a rectangular portion of the screen into a
  15090.   structure called a VBLOCK.  A pointer to this structure is called a
  15091.   VBLOCKPTR.  Here is the prototype:
  15092.  
  15093.  
  15094.      VBLOCKPTR VideoSave(int urow, int ucol, int lrow, int lcol)
  15095.  
  15096.   This function returns a VBLOCKPTR.  The VBLOCKPTR will be used to move or
  15097.   restore this saved region.  The first two arguments are the coordinates of
  15098.   the upper left hand corner of the rectangle to save (urow,ucol).  The last
  15099.   two arguments are the coordinates of the lower right hand corner of the
  15100.   rectangle (lrow,lcol).  There is no check to see if the coordinates are out
  15101.   of bounds.  You can use this function to save the base screen, and then use
  15102.   VideoRestore() to restore the base screen on exit.
  15103.  
  15104.   Example:
  15105.  
  15106.   #include "window.h"
  15107.  
  15108.   VBLOCKPTR v;
  15109.  
  15110.   main()
  15111.   {
  15112.     WindowInitializeSystem();
  15113.     v = VideoSave(1,1,25,80);   /* Save Rectangular region */
  15114.  
  15115.     /* Check if NULL */
  15116.     if (v == (VBLOCKPTR)0)
  15117.       VideoWriteString("Trouble saving video");
  15118.   }
  15119.  
  15120.   If there are no errors, VideoSave() returns a valid VBLOCKPTR.
  15121.  
  15122.   If there are errors VideoSave() returns a null VBLOCKPTR and sets the global
  15123.   integer window_error_code to the following value:
  15124.  
  15125.   NO_HEAP_MEM if there is not enough memory for the save buffer of the
  15126.   VBLOCKPTR.
  15127.  
  15128.  Page 259                     The C Window Library                    Page 259
  15129.  
  15130.   VideoMove()
  15131.   -----------
  15132.  
  15133.   The VideoMove() function moves a region saved by VideoSave() to a different
  15134.   location of the screen.  This location will be the new upper left hand corner
  15135.   of the rectangular region that was saved.  The move is not displayed until
  15136.   you call VideoRestore(), which is defined later.   Here is the prototype:
  15137.  
  15138.                void VideoMove(VBLOCKPTR v, int row, int col)
  15139.  
  15140.   The first argument is the VBLOCKPTR.  The second and third arguments are the
  15141.   new upper left hand position of the saved area.  There is NO check to see if
  15142.   the VBLOCKPTR exists, or the row or column are valid.
  15143.  
  15144.   Example:
  15145.  
  15146.   #include "window.h"
  15147.  
  15148.   VBLOCKPTR v;
  15149.  
  15150.   main()
  15151.   {
  15152.     WindowInitializeSystem();
  15153.     v = VideoSave(1,1,10,10);   /* Save Rectangular region defined by (1,1)
  15154.                                    (10,10) */
  15155.     VideoMove(v,1,10);
  15156.   }
  15157.  
  15158.   There is no return value for VideoMove().
  15159.  
  15160.  
  15161.  
  15162.  
  15163.   VideoRestore()
  15164.   --------------
  15165.  
  15166.   The VideoRestore() function takes a rectangular area of the screen saved with
  15167.   VideoSave() and redisplays the area.  Here is the prototype:
  15168.  
  15169.                      void VideoRestore(VBLOCKPTR v)
  15170.  
  15171.   The only argument is the VBLOCKPTR.  There is no check to see if the
  15172.   VBLOCKPTR is valid.
  15173.  
  15174.  
  15175.  
  15176.  
  15177.  
  15178.  
  15179.  
  15180.  
  15181.  
  15182.  
  15183.  
  15184.  Page 260                     The C Window Library                    Page 260
  15185.  
  15186.   Example:
  15187.  
  15188.  
  15189.   #include "window.h"
  15190.  
  15191.   VBLOCKPTR v;
  15192.  
  15193.   main()
  15194.   {
  15195.     WindowInitializeSystem();
  15196.     v = VideoSave(1,1,10,10);
  15197.     for (i=1;i<=10;i++)
  15198.       VideoWriteString("This is the save area.  Press a key to restore.",i,1);
  15199.     GET_KEY();
  15200.     VideoRestore(v);
  15201.   }
  15202.  
  15203.  
  15204.   There is no return value for VideoRestore().
  15205.  
  15206.  
  15207.  
  15208.  
  15209.   VideoFree()
  15210.   -----------
  15211.  
  15212.   The VideoFree() function frees a previously defined VBLOCKPTR.  Here is the
  15213.   prototype:
  15214.  
  15215.            void VideoFree(VBLOCKPTR v)
  15216.  
  15217.   The only argument is the VBLOCKPTR.  There is NO check to see if the
  15218.   VBLOCKPTR is valid,  therefore you must be very careful to call this function
  15219.   on a valid VBLOCKPTR.  If not, the heap will become corrupted.
  15220.  
  15221.   Example:
  15222.  
  15223.   #include "window.h"
  15224.  
  15225.   VBLOCKPTR v;
  15226.  
  15227.   main()
  15228.   {
  15229.     WindowInitializeSystem();
  15230.     v = VideoSave(1,1,10,10);
  15231.     for (i=1;i<=10;i++)
  15232.       VideoWriteString("This is the save area.  Press a key to restore.",i,1);
  15233.     GET_KEY();
  15234.     VideoRestore(v);
  15235.     VideoFree(v);
  15236.   }
  15237.  
  15238.   There is no return value for VideoFree().
  15239.  
  15240.  Page 261                     The C Window Library                    Page 261
  15241.  
  15242.                                CLEARING SCREENS
  15243.                                ----------------
  15244.  
  15245.   The following functions clears the visible video page, and clears regions of
  15246.   the visible screen.
  15247.  
  15248.  
  15249.  
  15250.   ClearScreen()
  15251.   -------------
  15252.  
  15253.   The ClearScreen() function clears the visible video page with a specified
  15254.   attribute and moves the screen cursor to position (1,1).  Here is the
  15255.   prototype:
  15256.  
  15257.                       void ClearScreen(int attr)
  15258.  
  15259.   The only argument is the video attribute to use.
  15260.  
  15261.   Example:
  15262.  
  15263.  
  15264.   #include "window.h"
  15265.  
  15266.   main()
  15267.   {
  15268.     WindowInitializeSystem();
  15269.  
  15270.     /* Clear the entire screen */
  15271.     ClearScreen(CREATE_VIDEO_ATTRIBUTE(black,white));
  15272.   }
  15273.  
  15274.   There is no return value for ClearScreen().
  15275.  
  15276.  
  15277.  
  15278.  
  15279.  
  15280.   ClearRegion()
  15281.   -------------
  15282.  
  15283.   This function clears a rectangular region of the screen.  Here is the
  15284.   prototype:
  15285.  
  15286.         void ClearRegion(int urow, int ucol, int lrow, int lcol, int attr)
  15287.  
  15288.   The first two arguments represent the coordinate of the upper left hand
  15289.   coordinates of the rectangular region to clear.  The third and fourth
  15290.   arguments represent the coordinate of the lower right hand corner of the
  15291.   rectangular region.  The last argument is the attribute to use.  There is no
  15292.   check to see if the coordinates are in bounds.
  15293.  
  15294.  
  15295.  
  15296.  Page 262                     The C Window Library                    Page 262
  15297.  
  15298.   Example:
  15299.  
  15300.   #include "window.h"
  15301.  
  15302.   main()
  15303.   {
  15304.     WindowInitializeSystem();
  15305.  
  15306.     /* Clear Region defined by (1,1) as the upper right hand corner and (10,10)
  15307.        as the lower right hand corner */
  15308.  
  15309.     ClearRegion(1,1,10,10,CREATE_VIDEO_ATTRIBUTE(black,white));
  15310.   }
  15311.  
  15312.  
  15313.   There is no return value for ClearRegion().
  15314.  
  15315.  
  15316.  
  15317.  
  15318.  
  15319.  
  15320.  
  15321.  
  15322.  
  15323.  
  15324.  
  15325.  
  15326.  
  15327.  
  15328.  
  15329.  
  15330.  
  15331.  
  15332.  
  15333.  
  15334.  
  15335.  
  15336.  
  15337.  
  15338.  
  15339.  
  15340.  
  15341.  
  15342.  
  15343.  
  15344.  
  15345.  
  15346.  
  15347.  
  15348.  
  15349.  
  15350.  
  15351.  
  15352.  Page 263                     The C Window Library                    Page 263
  15353.  
  15354.                                SCROLLING SCREENS
  15355.                                -----------------
  15356.  
  15357.   These functions scroll portions of the screen up or down.
  15358.  
  15359.  
  15360.  
  15361.   ScrollScreenUp()
  15362.   ----------------
  15363.  
  15364.   The ScrollScreenUp() function scrolls a rectangular portion of the screen up
  15365.   a specified number of lines.  Here is the prototype:
  15366.  
  15367.   void ScrollScreenUp(int numlines, int urow, int ucol, int lrow, int lcol,
  15368.                       int attr)
  15369.  
  15370.   The first argument is the number of lines to scroll the region.  The second
  15371.   and third arguments are the (row,col) coordinates of the upper left hand
  15372.   corner of the rectangular region to scroll.  The fourth and fifth arguments
  15373.   are the (row,col) of the lower right hand corner of the rectangular region.
  15374.   The last argument is the attribute to use for blank lines created when the
  15375.   region is scrolled.
  15376.  
  15377.  
  15378.   Example:
  15379.  
  15380.   #include "window.h"
  15381.  
  15382.   main()
  15383.   {
  15384.     WindowInitializeSystem();
  15385.     ScrollScreenUp(1,1,3,5,10,CREATE_VIDEO_ATTRIBUTE(black,white));
  15386.   }
  15387.  
  15388.   There is no return value for ScrollScreenUp().
  15389.  
  15390.  
  15391.  
  15392.   ScrollScreenDown()
  15393.   ------------------
  15394.  
  15395.   The ScrollScreenDown() function scrolls a rectangular portion of the screen
  15396.   down a specified number of lines.  Here is the prototype:
  15397.  
  15398.   void ScrollScreenDown(int numlines, int urow, int ucol, int lrow, int lcol,
  15399.                       int attr)
  15400.  
  15401.   The first argument is the number of lines to scroll the region.  The second
  15402.   and third arguments are the (row,col) coordinates of the upper left hand
  15403.   corner of the rectangular region to scroll.  The fourth and fifth arguments
  15404.   are the (row,col) of the lower right hand corner of the rectangular region.
  15405.   The last argument is the attribute to use for blank lines created when the
  15406.   region is scrolled.
  15407.  
  15408.  Page 264                     The C Window Library                    Page 264
  15409.  
  15410.   Example:
  15411.  
  15412.   #include "window.h"
  15413.  
  15414.   main()
  15415.   {
  15416.     WindowInitializeSystem();
  15417.     ScrollScreenDown(1,1,3,5,10,CREATE_VIDEO_ATTRIBUTE(black,white));
  15418.   }
  15419.  
  15420.   There is no return value for ScrollScreenDown().
  15421.  
  15422.  
  15423.  
  15424.  
  15425.  
  15426.  
  15427.  
  15428.  
  15429.  
  15430.  
  15431.  
  15432.  
  15433.  
  15434.  
  15435.  
  15436.  
  15437.  
  15438.  
  15439.  
  15440.  
  15441.  
  15442.  
  15443.  
  15444.  
  15445.  
  15446.  
  15447.  
  15448.  
  15449.  
  15450.  
  15451.  
  15452.  
  15453.  
  15454.  
  15455.  
  15456.  
  15457.  
  15458.  
  15459.  
  15460.  
  15461.  
  15462.  
  15463.  
  15464.  Page 265                     The C Window Library                    Page 265
  15465.  
  15466.                             CHANGING THE VIDEO MODE
  15467.                             -----------------------
  15468.  
  15469.   With The C Window Library, you can change the video mode at any time.  The
  15470.   video mode determines the width of the screen, and whether the screen is in
  15471.   text or graphics mode.
  15472.  
  15473.  
  15474.   SetVideoMode()
  15475.   --------------
  15476.  
  15477.   The SetVideoMode() function changes the video mode.  Here is a prototype:
  15478.  
  15479.           void SetVideoMode(int modenum)
  15480.  
  15481.   The only argument is the mode number.  Refer to the Video Paging section on
  15482.   page 5 for more information on mode numbers and what they display.
  15483.  
  15484.   When the video mode is changed, the screen is cleared.  This cannot be
  15485.   prevented.  You must redisplay any windows that were on the screen.  If the
  15486.   change of video mode results in a change in screen dimensions, then you must
  15487.   read the following sections on CHANGING THE NUMBER OF ROWS AND COLUMNS ON THE
  15488.   SCREEN.  Even though The C Window Library does not support graphics mode, you
  15489.   can change to graphics mode in The C Window Library,
  15490.  
  15491.   Example:
  15492.  
  15493.   #include "window.h"
  15494.  
  15495.   main()
  15496.   {
  15497.     WindowInitializeSystem();
  15498.     SetVideoMode(3);          /* Change to video mode 3 */
  15499.   }
  15500.  
  15501.   There is no return value for SetVideoMode().
  15502.  
  15503.  
  15504.  
  15505.  
  15506.  
  15507.  
  15508.  
  15509.  
  15510.  
  15511.  
  15512.  
  15513.  
  15514.  
  15515.  
  15516.  
  15517.  
  15518.  
  15519.  
  15520.  Page 266                     The C Window Library                    Page 266
  15521.  
  15522.              CHANGING THE NUMBER OF ROWS AND COLUMNS ON THE SCREEN
  15523.              -----------------------------------------------------
  15524.  
  15525.  
  15526.   Changing rows
  15527.   -------------
  15528.  
  15529.   With The C Window Library, you can change the number of rows on the video
  15530.   screen.  However, there are some things to watch out for when changing the
  15531.   number of rows, especially if you have windows displayed on the screen.  If
  15532.   you are not using any window related functions, you can change the number of
  15533.   displayable rows safely by doing two things:
  15534.  
  15535.   a) Call the SetVideoRows() function to change the number of rows.
  15536.  
  15537.   b) Call AdjustGlobalData() to adjust the global variables used by The C
  15538.      Window Library that keep track of the screen dimensions.
  15539.  
  15540.  
  15541.   If you are going to create or have created windows you must do three things:
  15542.  
  15543.   a)  Make sure that any window defined will have valid coordinates when the
  15544.       number of rows are changed.  There may be cases where a window occupies a
  15545.       row that exists in one screen mode, but the row does not exist in another
  15546.       screen mode.  If there are windows that will have invalid coordinates in
  15547.       another screen configuration, you must resize them, remove them, or
  15548.       whatever it takes to resolve the invalid coordinates.
  15549.  
  15550.   b)  Call the SetVideoRows() function.
  15551.  
  15552.   c)  Call the AdjustScreenInfo() function.  This function adjusts all global
  15553.       variables defined in The C Window Library to reflect the new number of
  15554.       rows.
  15555.  
  15556.   Whether there are or are not windows defined, the visible video page MUST be
  15557.   page 0 before changing the number of screen rows.
  15558.  
  15559.  
  15560.  
  15561.   AdjustScreenInfo()
  15562.   ------------------
  15563.  
  15564.   This function must be called after SetVideoRows() is called if you are
  15565.   going to, or have initialized and/or displayed windows.  Here is the
  15566.   prototype:
  15567.  
  15568.                      int AdjustScreenInfo(int page)
  15569.  
  15570.   The only argument is the video page to adjust to the new screen height.
  15571.   Because of the new dimension of the screen, there has to be a reshuffling of
  15572.   a few global arrays, constants, variables, etc.  The AdjustScreenInfo()
  15573.   function does just this.  If you do not call AdjustScreenInfo(), you may see
  15574.   problems if you try to manipulate windows on the new screen.
  15575.  
  15576.  Page 267                     The C Window Library                    Page 267
  15577.  
  15578.   See SetVideoRows() for an example of AdjustScreenInfo().
  15579.  
  15580.   If there are no errors, AdjustScreenInfo() returns NO_ERROR.
  15581.  
  15582.   If there are errors, AdjustScreenInfo() returns the following value:
  15583.  
  15584.   NO_HEAP_MEM if there is not enough memory to allocate for the global arrays,
  15585.   structures, etc.
  15586.  
  15587.  
  15588.  
  15589.  
  15590.   AdjustGlobalData()
  15591.   ------------------
  15592.  
  15593.   The AdjustGlobalData() function should be called after you have changed the
  15594.   number of video rows using SetVideoRows() (defined below).  This resets the
  15595.   global variables necessary for non-window functions to execute properly.
  15596.   Here is the prototype:
  15597.  
  15598.                   void AdjustGlobalData(void)
  15599.  
  15600.   There are no arguments and no return value for AdjustGlobalData().  If you
  15601.   have called AdjustScreenInfo(), you do not have to call AdjustGlobalData().
  15602.  
  15603.   See below for an example of AdjustGlobalData().
  15604.  
  15605.  
  15606.  
  15607.  
  15608.  
  15609.   SetVideoRows()
  15610.   --------------
  15611.  
  15612.   The SetVideoRows() function changes the number of video rows on the screen.
  15613.   Here is a list of video adapters and there row number capabilities:
  15614.  
  15615.       Video Type                 Number of Rows
  15616.                                     Possible
  15617.       ----------                 --------------
  15618.       CGA, MDA, Hercules              25
  15619.  
  15620.       EGA                            25, 43
  15621.  
  15622.       MCGA                           25, 50
  15623.  
  15624.       VGA                            12, 14, 21, 25, 28, 43, 50
  15625.  
  15626.   The list above are the values SetVideoRows() uses, depending on the adapter
  15627.   that The C Window Library has detected.  If your video card supports a row
  15628.   configuration that is not supported by the SetVideoRows() function,  consult
  15629.   the 'Changing columns' section and proceed as if you are changing the number
  15630.   of columns.
  15631.  
  15632.  Page 268                     The C Window Library                    Page 268
  15633.  
  15634.   Here is the prototype for SetVideoRows():
  15635.  
  15636.              int SetVideoRows(int numrows, int modeflag)
  15637.  
  15638.   The first argument is the number of screen rows.  The modeflag tells whether
  15639.   the video mode should be reset.  If modeflag is 0, the video mode is not
  15640.   reset.  Any other value for modeflag will cause a video mode reset.  This
  15641.   reset may or may not be necessary, so experiment with both values for
  15642.   modeflag.
  15643.  
  15644.   Example:
  15645.  
  15646.   #include "window.h"
  15647.  
  15648.   main()
  15649.   {
  15650.     WindowInitializeSystem();
  15651.     ClearScreen(CREATE_VIDEO_ATTRIBUTE(black,white));
  15652.     VideoWriteString("Press a key to change to a new video mode",1,1);
  15653.     GET_KEY();
  15654.     if (VGA_MODE_ON || MCGA_MODE_ON)
  15655.       SetVideoRows(50,0);
  15656.     else
  15657.     if (EGA_MODE_ON)
  15658.       SetVideoRows(43,0);
  15659.     else
  15660.     {
  15661.       VideoWriteString("Hardware does not support changing video rows",2,1);
  15662.       exit(0);
  15663.     }
  15664.  
  15665.     AdjustGlobalData();
  15666.     VideoWriteString("Press a key again to change to 25 lines",2,1);
  15667.     GET_KEY();
  15668.     SetVideoRows(25,0);
  15669.     AdjustGlobalData();
  15670.   }
  15671.  
  15672.  
  15673.   The example above uses the constants VGA_MODE_ON, MCGA_MODE_ON, and
  15674.   EGA_MODE_ON.  These constants are discussed in the VIDEO MACROS section.
  15675.  
  15676.  
  15677.   Here is another example, but now we have a window on the screen.
  15678.  
  15679.  
  15680.  
  15681.  
  15682.  
  15683.  
  15684.  
  15685.  
  15686.  
  15687.  
  15688.  Page 269                     The C Window Library                    Page 269
  15689.  
  15690.   Example:
  15691.  
  15692.   #include "window.h"
  15693.   #define NORM  CREATE_VIDEO_ATTRIBUTE(black,white)
  15694.  
  15695.   WPOINTER w;
  15696.  
  15697.   main()
  15698.   {
  15699.     WindowInitializeSystem();
  15700.     WindowSaveInitial(0);
  15701.     w = WindowInitialize(BORDER,1,1,30,10,NORM,NORM,SINGLEBOX);
  15702.     WindowOpen(w);
  15703.     WindowDisplay(w,1,NOEFFECT);
  15704.     WindowWriteString(w,"Press a key to change rows",1,1);
  15705.     GET_KEY();
  15706.     if (VGA_MODE_ON || MCGA_MODE_ON)
  15707.       SetVideoRows(50,0);
  15708.     else
  15709.     if (EGA_MODE_ON)
  15710.       SetVideoRows(43,0);
  15711.     else
  15712.     {
  15713.       WindowWriteString(w,"Cannot change rows",1,1);
  15714.       exit(0);
  15715.     }
  15716.  
  15717.     /* Adjust the screen information */
  15718.     AdjustScreenInfo(0);
  15719.  
  15720.     /* OK to adjust to new height */
  15721.     WindowResizeHeight(w,40,ANCHORTOP);
  15722.  
  15723.     WindowWriteString(w,"Now press a key to change back",2,1);
  15724.     GET_KEY();
  15725.  
  15726.     /*  First we must resize window */
  15727.     WindowResizeHeight(w,10,ANCHORTOP);
  15728.  
  15729.     SetVideoRows(25,0);
  15730.  
  15731.     AdjustScreenInfo(0);
  15732.  
  15733.   }
  15734.  
  15735.   Note the use of AdjustScreenInfo() after a reset is made.
  15736.  
  15737.   If there are no errors, SetVideoRows() returns no errors.
  15738.  
  15739.   If there are errors SetVideoRows() returns the following value:
  15740.  
  15741.   INVALID_ROWS if the number of rows is not supported for the detected monitor
  15742.   type.
  15743.  
  15744.  Page 270                     The C Window Library                    Page 270
  15745.  
  15746.   Changing columns
  15747.   ----------------
  15748.  
  15749.   The number of columns can be changed, but there are two things to watch out
  15750.   for.  First, to change from 40 column mode to 80 column mode or vice-versa,
  15751.   is a matter of changing the video mode.  Changing the video mode from 40 to
  15752.   80 column mode or from 80 to 40 requires a BIOS function that is present on
  15753.   all systems that support 40 column mode.
  15754.  
  15755.  
  15756.  
  15757.   40 column and 80 column modes
  15758.   -----------------------------
  15759.  
  15760.   To change to 40 column mode do the following:
  15761.  
  15762.   SetVideoMode(0);   /* this changes to 40 column black and white mode */
  15763.  
  15764.        or
  15765.  
  15766.   SetVideoMode(1);   /* this changes to 40 column color mode */
  15767.  
  15768.   The example above only works if you have a CGA, EGA, MCGA, or VGA card.
  15769.  
  15770.  
  15771.  
  15772.   To change to 80 column mode do the following:
  15773.  
  15774.   SetVideoMode(2);  /* this changes to Black and White 80 column mode */
  15775.  
  15776.        or
  15777.  
  15778.   SetVideoMode(3);  /* use this for color 80 column mode */
  15779.  
  15780.        or
  15781.  
  15782.   SetVideoMode(7);  /* use this for mono cards */
  15783.  
  15784.   SetVideoMode(7) works for all adapters, while SetVideoMode(2) and
  15785.   SetVideoMode(3) works only for CGA, EGA, MCGA, or VGA cards.
  15786.  
  15787.  
  15788.   Modes higher than 80 columns
  15789.   ----------------------------
  15790.  
  15791.   There are video systems that support video modes greater than 80 columns.
  15792.   The problem is that for each different brand of video adapter, there is a
  15793.   unique way of changing to a higher column mode.  Most of these adapters
  15794.   support an additional BIOS function that must be called to change to any
  15795.   screen column mode higher than 80.  Therefore, it is up to you (the
  15796.   programmer) to find out how to change the video system from 80 columns to a
  15797.   higher column mode.  Once you are familiar with how to do this, changing the
  15798.   number of columns is almost the same as changing the number of rows.
  15799.  
  15800.  Page 271                     The C Window Library                    Page 271
  15801.  
  15802.   If you are using any window related functions, you can change the number
  15803.   of displayable columns safely by doing three things:
  15804.  
  15805.   a) Call the appropriate routine to change the number of columns.  If this is
  15806.      a call to SetVideoMode(), the screen will be cleared.
  15807.  
  15808.   b) Call AdjustScreenInfo() to adjust the global variables used by The C
  15809.      Window Library that keep track of the screen dimensions.
  15810.  
  15811.   c) Readjust and/or redraw any windows on the screen.  Make sure that all
  15812.      windows fit on the screen, whether they are hidden or not.
  15813.  
  15814.   If you are not using any windows in your application, replace the call to
  15815.   AdjustScreenInfo() in step b) with a call to AdjustGlobalData().
  15816.  
  15817.   This example works for the ATI VGA card.  This changes the mode to 132
  15818.   columns:
  15819.  
  15820.   #include "window.h"
  15821.   #define NORM  CREATE_VIDEO_ATTRIBUTE(black,white)
  15822.  
  15823.   WPOINTER w;
  15824.  
  15825.   main()
  15826.   {
  15827.     WindowInitializeSystem();
  15828.     WindowSaveInitial(0);
  15829.     w = WindowInitialize(BORDER,1,1,30,10,NORM,NORM,SINGLEBOX);
  15830.     WindowOpen(w);
  15831.     WindowDisplay(w,1,NOEFFECT);
  15832.     WindowWriteString(w,"Press a key to change columns",1,1);
  15833.     GET_KEY();
  15834.  
  15835.     /* Set Video Mode to 132 rows x 25 columns (Works for ATI VGA card) */
  15836.     SetVideoMode(0x23);
  15837.     /* Adjust the screen information and redisplay window */
  15838.     AdjustScreenInfo(0);
  15839.     WindowDisplay(w,1,NOEFFECT);
  15840.  
  15841.     /* OK to adjust to new height */
  15842.     WindowResizeWidth(w,100,ANCHORLEFT);
  15843.  
  15844.     WindowWriteString(w,"Now press a key to change back",2,1);
  15845.     GET_KEY();
  15846.  
  15847.     /*  First we must resize window */
  15848.     WindowResizeWidth(w,30,ANCHORLEFT);
  15849.  
  15850.     /* Set back to 80 column mode */
  15851.     SetVideoMode(3);
  15852.     AdjustScreenInfo(0);
  15853.     WindowDisplay(w,1,NOEFFECT);
  15854.   }
  15855.  
  15856.  Page 272                     The C Window Library                    Page 272
  15857.  
  15858.                               CURSOR MANIPULATION
  15859.                               -------------------
  15860.  
  15861.   The functions defined in this section manipulate the cursor.  The
  15862.   following functions can be called without calling WindowInitializeSystem().
  15863.  
  15864.  
  15865.  
  15866.  
  15867.   MoveCursor()
  15868.   ------------
  15869.   This function moves the cursor to a different location.  Here is the
  15870.   prototype:
  15871.  
  15872.              void MoveCursor(int row, int col, int page)
  15873.  
  15874.   The first two arguments are the row and column positions of where to move the
  15875.   cursor.  The last argument is the video page of the cursor you want to move.
  15876.  
  15877.  
  15878.   Example:
  15879.  
  15880.   #include "window.h"
  15881.  
  15882.   main()
  15883.   {
  15884.     MoveCursor(1,5,0);    /* Move cursor to row 1 column 5 on video page 0 */
  15885.   }
  15886.  
  15887.   There is no return value for MoveCursor().
  15888.  
  15889.  
  15890.  
  15891.  
  15892.  
  15893.   ChangeCursor()
  15894.   --------------
  15895.  
  15896.   The ChangeCursor() function changes the shape of the cursor.  The shape of
  15897.   the cursor is determined by its starting and ending scan lines.  Here is a
  15898.   prototype:
  15899.  
  15900.              void ChangeCursor(unsigned startline, unsigned endline)
  15901.  
  15902.   The first argument is the starting scan line and the second argument is the
  15903.   ending scan line.  For monochrome systems, there are 12 scan lines numbered 0
  15904.   thru 11, while on color systems there are 8 scan lines numbered 0 thru 7.
  15905.   The starting scan line is the top line of the cursor, and the ending scan
  15906.   line is the last line of the cursor.  There is no check to see if the
  15907.   starting scan line and the ending scan lines are valid.
  15908.  
  15909.  
  15910.  
  15911.  
  15912.  Page 273                     The C Window Library                    Page 273
  15913.  
  15914.   Example:
  15915.  
  15916.   #include "window.h"
  15917.  
  15918.   main()
  15919.   {
  15920.     WindowInitializeSystem();
  15921.     ChangeCursor(6,7);  /* This is an underline cursor */
  15922.     GET_KEY();
  15923.     ChangeCursor(0,7);  /* This is a thick cursor */
  15924.   }
  15925.  
  15926.   There is no return for ChangeCursor().
  15927.  
  15928.  
  15929.  
  15930.  
  15931.   GetCursorShape()
  15932.   ----------------
  15933.  
  15934.   This function returns the shape of the cursor in scan lines.  Here is the
  15935.   prototype:
  15936.  
  15937.           void GetCursorShape(unsigned *startline, unsigned *endline)
  15938.  
  15939.   When this function returns, the staring scan line is placed in the integer
  15940.   pointed to by scanline, and the ending scan line is placed in the integer
  15941.   pointed to by endline.
  15942.  
  15943.   Example:
  15944.  
  15945.   #include "window.h"
  15946.  
  15947.   main()
  15948.   {
  15949.     int start, end;
  15950.     WindowInitializeSystem();
  15951.     GetCursorShape(&start, &end);
  15952.     VideoPrintf("\nThe starting scan line is %d\nThe ending scan line is %d",
  15953.                  start,end);
  15954.   }
  15955.  
  15956.   There is no return value for GetCursorShape().
  15957.  
  15958.  
  15959.  
  15960.   GetCursorPosition()
  15961.   -------------------
  15962.  
  15963.   This function gets the current cursor position.  Here is the prototype:
  15964.  
  15965.          void GetCursorPosition(int *row, int *col, int page)
  15966.  
  15967.  
  15968.  Page 274                     The C Window Library                    Page 274
  15969.  
  15970.   The first argument is a pointer to an integer that will be set to the current
  15971.   row.  The second argument is a pointer to an integer that will be set to the
  15972.   current column.  The last argument is the video page of the cursor.
  15973.  
  15974.   Example:
  15975.  
  15976.  
  15977.   #include "window.h"
  15978.  
  15979.   main()
  15980.   {
  15981.     int row,col;
  15982.     MoveCursor(10,15);
  15983.     GetCursorPosition(&row,&col,0);
  15984.     WindowInitializeSystem();
  15985.     VideoPrintf("\nThe row of the cursor is %d\nThe column is %d",
  15986.                  row,col);
  15987.   }
  15988.  
  15989.  
  15990.   There is no return value for GetCursorPosition().
  15991.  
  15992.  
  15993.  
  15994.  
  15995.  
  15996.   The following functions serve as shortcuts in changing the cursor shape.
  15997.  
  15998.  
  15999.   HideCursor()
  16000.   ------------
  16001.  
  16002.   Hides the cursor on the screen.  Here is the prototype:
  16003.  
  16004.                        void HideCursor(void)
  16005.  
  16006.  
  16007.   BlockCursor()
  16008.   -------------
  16009.  
  16010.   Displays the cursor as a thick block.
  16011.  
  16012.                        void BlockCursor(void)
  16013.  
  16014.   ThinCursor()
  16015.   ------------
  16016.  
  16017.   Displays the cursor as an underline cursor.
  16018.  
  16019.                        void ThinCursor(void)
  16020.  
  16021.  
  16022.  
  16023.  
  16024.  Page 275                     The C Window Library                    Page 275
  16025.  
  16026.   Example:
  16027.  
  16028.  
  16029.   #include "window.h"
  16030.  
  16031.   main()
  16032.   {
  16033.     WindowInitializeSystem();
  16034.     MoveCursor(1,1,0);
  16035.     VideoWriterString("Press a key to hide the cursor",1,1);
  16036.     GET_KEY();
  16037.     HideCursor();
  16038.     VideoWriterString("Press a key to change cursor to a block",2,1);
  16039.     GET_KEY();
  16040.     BlockCursor();
  16041.     VideoWriterString("Press a key to change cursor to a thin cursor",3,1);
  16042.     GET_KEY();
  16043.     ThinCursor();
  16044.   }
  16045.  
  16046.  
  16047.   There are no return values for HideCursor(), BlockCursor(), or ThinCursor().
  16048.  
  16049.  
  16050.  
  16051.  
  16052.  
  16053.  
  16054.  
  16055.  
  16056.  
  16057.  
  16058.  
  16059.  
  16060.  
  16061.  
  16062.  
  16063.  
  16064.  
  16065.  
  16066.  
  16067.  
  16068.  
  16069.  
  16070.  
  16071.  
  16072.  
  16073.  
  16074.  
  16075.  
  16076.  
  16077.  
  16078.  
  16079.  
  16080.  Page 276                     The C Window Library                    Page 276
  16081.  
  16082.                            GETTING VIDEO INFORMATION
  16083.                            -------------------------
  16084.  
  16085.   You can get information about the video configuration by calling the
  16086.   GetVideoBiosInfo() function.
  16087.  
  16088.  
  16089.   VIDEO_CONFIG structure
  16090.   ----------------------
  16091.  
  16092.   To get information about the video configuration, you must pass a pointer
  16093.   to a VIDEO_CONFIG structure.  This structure is defined as follows:
  16094.  
  16095.  
  16096.       typedef struct
  16097.       {
  16098.         unsigned int video_mode;          /* Current video mode */
  16099.         unsigned int cursor_startline;    /* Starting scan line of cursor */
  16100.         unsigned int cursor_endline;      /* Ending scan line of cursor */
  16101.         unsigned int cursor_row;          /* Screen row of cursor */
  16102.         unsigned int cursor_col;          /* Column of cursor */
  16103.         unsigned int video_page;          /* Current visible video page */
  16104.         unsigned int video_pagesize;      /* Size in bytes of the video page */
  16105.         unsigned int video_rows;          /* Number of displayable rows */
  16106.         unsigned int video_cols;          /* Number of displayable columns */
  16107.         unsigned int char_height;         /* Height (in scan lines) of a
  16108.                                              character  */
  16109.         unsigned int crt_port_address;    /* Address of CRT status port */
  16110.         unsigned int crt_mode_setting;    /* Current CRT Mode Setting   */
  16111.         unsigned int crt_color_setting;   /* Current CRT color settings */
  16112.       } VIDEO_CONFIG;
  16113.  
  16114.  
  16115.  
  16116.   GetVideoBiosInfo()
  16117.   ------------------
  16118.  
  16119.   This function returns information about the current video configuration.
  16120.   Here is the prototype:
  16121.  
  16122.              void GetVideoBiosInfo(VIDEO_CONFIG *v)
  16123.  
  16124.   The only argument is a pointer to a VIDEO_CONFIG structure.  This structure
  16125.   is filled in with the appropriate values.
  16126.  
  16127.  
  16128.  
  16129.  
  16130.  
  16131.  
  16132.  
  16133.  
  16134.  
  16135.  
  16136.  Page 277                     The C Window Library                    Page 277
  16137.  
  16138.   Example:
  16139.  
  16140.   #include "window.h"
  16141.  
  16142.   VIDEO_CONFIG v;
  16143.  
  16144.   main()
  16145.   {
  16146.     WindowInitializeSystem();
  16147.  
  16148.     /* Get video information */
  16149.     ClearScreen(CREATE_VIDEO_ATTRIBUTE(black,white));
  16150.     GetVideoBiosInfo(&v);
  16151.     VideoPrintf("The video mode is %d\n"
  16152.                 "The starting scan line of the cursor is %d\n"
  16153.                 "The ending scan line of the cursor is %d \n"
  16154.                 "The row of the cursor is %d \n"
  16155.                 "The column of the cursor is %d\n"
  16156.                 "The video page is %d\n"
  16157.                 "The size of the video page is %d\n"
  16158.                 "The number of rows is %d\n"
  16159.                 "The number of columns is %d\n"
  16160.                 "The height of the characters is %d\n",
  16161.                 v.video_mode, v.cursor_startline, v.cursor_endline,
  16162.                 v.cursor_row,v.cursor_col,
  16163.                 v.video_page, v.video_pagesize, v.video_rows, v.video_cols,
  16164.                 v.char_height);
  16165.   }
  16166.  
  16167.  
  16168.   There is no return value for GetVideoBiosInfo().
  16169.  
  16170.  
  16171.  
  16172.  
  16173.  
  16174.  
  16175.  
  16176.  
  16177.  
  16178.  
  16179.  
  16180.  
  16181.  
  16182.  
  16183.  
  16184.  
  16185.  
  16186.  
  16187.  
  16188.  
  16189.  
  16190.  
  16191.  
  16192.  Page 278                     The C Window Library                    Page 278
  16193.  
  16194.                                  TIMED DELAYS
  16195.                                  ------------
  16196.  
  16197.   One of the problems that has been addressed in The C Window Library is the
  16198.   lack of a delay() function in most C compiler packages.  The delay() function
  16199.   delays program execution for a certain number of milliseconds.  Borland's
  16200.   Turbo C compiler is one of the few that has a delay() function.  The other
  16201.   compilers may have a sleep() function, but usually these functions do not
  16202.   have millisecond accuracy.
  16203.  
  16204.   One of the problems was to write a delay() function that would work for all
  16205.   the major C compilers, work with millisecond accuracy, work for any speed
  16206.   PC, and last but not least, without using floating point arithmetic.  This
  16207.   function was written in assembly language for accuracy.  The use of the
  16208.   delay() is used extensively in displaying and hiding windows with certain
  16209.   special effects.
  16210.  
  16211.  
  16212.   delay()
  16213.   -------
  16214.  
  16215.   The delay() function delays the program for a certain number of milliseconds.
  16216.   Here is the prototype:
  16217.  
  16218.                 void delay(unsigned millisecs)
  16219.  
  16220.   The only argument is the number of milliseconds to delay.  If you are using
  16221.   the Turbo C version of The C Window Library, this function is already
  16222.   included in the Turbo C library.  However, if you are using another compiler
  16223.   you now have a delay() function!
  16224.  
  16225.  
  16226.   Example:
  16227.  
  16228.   main()
  16229.   {
  16230.     WindowInitializeSystem();
  16231.     delay(50);   /* Delay for 50 milliseconds */
  16232.   }
  16233.  
  16234.   You must call WindowInitializeSystem() before using delay().
  16235.  
  16236.   There is no return value for delay().
  16237.  
  16238.  
  16239.  
  16240.  
  16241.  
  16242.  
  16243.  
  16244.  
  16245.  
  16246.  
  16247.  
  16248.  Page 279                     The C Window Library                    Page 279
  16249.  
  16250.                                 SOUND FUNCTIONS
  16251.                                 ---------------
  16252.  
  16253.   The C Window Library also supports sound functions for compilers that are
  16254.   lacking these functions.
  16255.  
  16256.  
  16257.   sound() and nosound()
  16258.   ---------------------
  16259.  
  16260.   The sound() function sounds a tone with a specified frequency in Hertz
  16261.   (cycles per second).  Here is a prototype:
  16262.  
  16263.                        void sound(unsigned frequency)
  16264.  
  16265.   The nosound() function turns off the tone generated by the sound() function.
  16266.  
  16267.  
  16268.     Example:
  16269.  
  16270.     #include "window.h"
  16271.  
  16272.     main()
  16273.     {
  16274.       unsigned i;
  16275.       WindowInitializeSystem();
  16276.       for (i=100;i<=1000;i++)
  16277.         sound(i);
  16278.       for(i=1000;i>=100;i--)
  16279.         sound(i);
  16280.       nosound();
  16281.     }
  16282.  
  16283.   Note for Turbo users:
  16284.  
  16285.   You should include "dos.h" in your files that contain sound() and nosound().
  16286.   All other compilers should include "window.h".
  16287.  
  16288.   Note for Power C users:
  16289.   If you are using the Power C compiler, you must include "window.h" or any
  16290.   file that includes window.h after bios.h.  This is to ensure that the linker
  16291.   does not get confused with the Power C function  called sound(), which works
  16292.   differently than the sound() function defined above.
  16293.  
  16294.  
  16295.  
  16296.   MakeSound()
  16297.   -----------
  16298.  
  16299.   The MakeSound() function sounds a tone for a duration of time.  Here is the
  16300.   prototype:
  16301.  
  16302.            void MakeSound(unsigned freq, unsigned millisec)
  16303.  
  16304.  Page 280                     The C Window Library                    Page 280
  16305.  
  16306.   where freq, is the frequency of the tone (in Hertz) and millisec is the
  16307.   number of milliseconds to sound the tone.
  16308.  
  16309.  
  16310.   Example:
  16311.   --------
  16312.  
  16313.   #include "window.h"
  16314.  
  16315.   main()
  16316.   {
  16317.     WindowInitializeSystem();
  16318.     /* Produce a 440 Hertz tone for 3 seconds */
  16319.     MakeSound(440,3000);
  16320.   }
  16321.  
  16322.   There is no error return for this function.
  16323.  
  16324.  
  16325.  
  16326.  
  16327.  
  16328.  
  16329.  
  16330.  
  16331.  
  16332.  
  16333.  
  16334.  
  16335.  
  16336.  
  16337.  
  16338.  
  16339.  
  16340.  
  16341.  
  16342.  
  16343.  
  16344.  
  16345.  
  16346.  
  16347.  
  16348.  
  16349.  
  16350.  
  16351.  
  16352.  
  16353.  
  16354.  
  16355.  
  16356.  
  16357.  
  16358.  
  16359.  
  16360.  Page 281                     The C Window Library                    Page 281
  16361.  
  16362.                                 ERROR HANDLING
  16363.                                 --------------
  16364.  
  16365.   Whenever an error has occurred in The C Window Library, a user defined error
  16366.   function can be called.
  16367.  
  16368.  
  16369.   The window_error_func function pointer
  16370.   --------------------------------------
  16371.  
  16372.   The window_error_func function pointer can point to an error function that
  16373.   is performed whenever there is an error encountered in one of The C Window
  16374.   Library functions.  If the global variable check_existence_flag is set to 1
  16375.   and there is an error, The C Window Library will automatically call
  16376.   window_error_func.  Here is the prototype:
  16377.  
  16378.        void (*window_error_func)(int errcode, char *sourcefile, int sourceline,
  16379.                                  char *funcname)
  16380.  
  16381.   The errcode is one of the defined error codes included in The C Window
  16382.   Library.  Refer to page 6 of the main documentation for more information of
  16383.   the error codes and their definitions.  The second argument is the name of
  16384.   the file where the error occurred.  Only users with the source code to The
  16385.   C Window Library will have access to this file.  The third argument is the
  16386.   offending line in the source file of where the error occurred.  The last
  16387.   argument is the name of the function of where the error occurred.
  16388.  
  16389.   By default window_error_func points to a void null function (VOIDNULLFN),
  16390.   therefore no error function is called.
  16391.  
  16392.       Here is an example of how to implement automatic error checking:
  16393.  
  16394.   #include "window.h"
  16395.   #define WHITEONRED CREATE_VIDEO_ATTRIBUTE(red,white)
  16396.   void custom_error_func(int, char *, int, char *);
  16397.  
  16398.   WPOINTER w, error_window;
  16399.   void initialize_error();
  16400.   main()
  16401.   {
  16402.     WindowInitializeSystem();
  16403.     WindowSaveInitial(0);
  16404.     window_error_func = custom_error_func;  /* Assign error function */
  16405.     initialize_error();
  16406.     WindowOpen(w);               /* will be flagged for an error */
  16407.   }
  16408.  
  16409.   void initialize_error()    /* Initialize error window and error handler */
  16410.   {
  16411.     error_window =
  16412.           WindowInitialize(BORDER,1,1,60,5,WHITEONRED,WHITEONRED,SINGLEBOX);
  16413.     WindowOpen(error_window);
  16414.   }
  16415.  
  16416.  Page 282                     The C Window Library                    Page 282
  16417.  
  16418.   void custom_error_func(int errcode, char *sourcefile, int sourceline,
  16419.                          char *funcname)
  16420.   {
  16421.     int ch;
  16422.     MakeSound(100,500);           /* Produce an error beep */
  16423.     if (errcode == NO_HEAP_MEM)   /* Always check for the heap memory error
  16424.                                      separately */
  16425.     {
  16426.       VideoWriteString("You have ran out of Heap Memory",1,1);
  16427.       VideoWriteString(
  16428.         "Press 'Q' to quit program, Any other key to Continue...",2,1);
  16429.     }
  16430.  
  16431.     else                         /* Display error window */
  16432.     {
  16433.       WindowClear(error_window);
  16434.       WindowDisplay(error_window,1,EXPLODE);
  16435.       WindowPrintf(error_window,
  16436.        "Error Code: %d\nSource File: %s\nSource Line %d\nError Occurred in %s",
  16437.        errcode,sourcefile,sourceline,funcname);
  16438.       WindowWriteString(error_window,
  16439.         "Press 'Q' to quit program, Any other key to Continue...",5,1);
  16440.     }
  16441.  
  16442.     ch = GET_KEY();
  16443.     if (ch == 'Q' || ch == 'q')
  16444.       exit(0);
  16445.     else
  16446.     if (errcode != NO_HEAP_MEM)
  16447.       WindowHide(error_window,CONTRACT);
  16448.   }
  16449.  
  16450.  
  16451.   The above example initializes an error window and sets the window_error_func
  16452.   function pointer to point to the function custom_error_func().  Whenever an
  16453.   error occurs in The C Window Library, custom_error_func() will be called.
  16454.  
  16455.   Please note the check to see if the NO_HEAP_MEM error has occurred.  It is
  16456.   important that you check for this error condition separately.  The reason for
  16457.   this is that if there is not enough heap memory, you may inadvertently call a
  16458.   function in your error handler that calls on malloc() or any of the other
  16459.   memory allocation related functions.  This will either freeze your system,
  16460.   or more peculiarly, cause your error handler to be called in an infinite
  16461.   loop because of the repeated failing calls to malloc() or its related
  16462.   functions.  In the latter case, you will run out of stack space.
  16463.  
  16464.   If you want to unassign the window_error_code function pointer, use the
  16465.   following line in your code:
  16466.  
  16467.                     window_error_func = VOIDNULLFN;
  16468.  
  16469.  
  16470.  
  16471.  
  16472.  Page 283                     The C Window Library                    Page 283
  16473.  
  16474.                   USING A MOUSE WITH THE C WINDOW LIBRARY
  16475.                   ---------------------------------------
  16476.  
  16477.   With The C Window Library, you can create applications that use a Microsoft
  16478.   compatible mouse to select from popup, pulldown, and bar menus.
  16479.  
  16480.  
  16481.   Installing the Mouse Library
  16482.   ----------------------------
  16483.  
  16484.   Before using the mouse library, make sure that you read the README file
  16485.   concerning installing the mouse library.
  16486.  
  16487.  
  16488.   Include files
  16489.   -------------
  16490.  
  16491.   The only include file needed is cwlmouse.h.  This file also includes
  16492.   window.h.
  16493.  
  16494.  
  16495.  
  16496.   Initializing the Mouse with MouseInitializeSystem()
  16497.   ---------------------------------------------------
  16498.  
  16499.   Before you can use a mouse, you must initialize it by calling
  16500.   MouseInitializeSystem().  This function tests for a Microsoft compatible
  16501.   mouse and returns a value denoting whether a mouse is found.  Here is the
  16502.   prototype:
  16503.  
  16504.      int MouseInitializeSystem(int intype, int *button, int hpos, int vpos)
  16505.  
  16506.   The first argument informs MouseInitializeSystem() to whether you just want
  16507.   to test to see if a mouse is installed and not to activate the mouse, or to
  16508.   not only test for the mouse, but to activate it.  If the first argument is
  16509.   MOUSE_TEST, MouseInitializeSystem() will just return an integer denoting
  16510.   whether a mouse is found.  If the first argument is MOUSE_FULL_INSTALL, not
  16511.   only is a status returned, but the mouse will be activated.
  16512.  
  16513.   The second argument is a pointer to an integer that will contain the number
  16514.   of buttons that the mouse has.  This number will usually be 2 or 3.
  16515.  
  16516.   The third and fourth arguments are the screen coordinates of where to place
  16517.   the mouse cursor on the screen.  The third argument is the row, and the
  16518.   fourth argument is the column to place the mouse cursor.
  16519.  
  16520.   MouseInitializeSystem() returns NOMOUSE if a mouse is not installed, or
  16521.   MOUSEFOUND if a mouse is installed.
  16522.  
  16523.   MouseInitializeSystem() must be called after calling WindowInitializeSystem()
  16524.   for it to work properly.
  16525.  
  16526.  
  16527.  
  16528.  Page 284                     The C Window Library                    Page 284
  16529.  
  16530.   Turning off the mouse with MouseRestoreSystem()
  16531.   -----------------------------------------------
  16532.  
  16533.   Before terminating a program that has called MouseInitializeSystem() you
  16534.   should call MouseRestoreSystem().  This function returns the state of the
  16535.   mouse before calling MouseInitializeSystem().  If you do not call
  16536.   MouseRestoreSystem(), the mouse will still be 'alive', even though the
  16537.   application has terminated.  Here is the prototype:
  16538.  
  16539.                      int MouseRestoreSystem(void)
  16540.  
  16541.   If the mouse was not initialized previously with MouseInitializeSystem(),
  16542.   MouseRestoreSystem() returns NOMOUSE, otherwise the return value is NO_ERROR.
  16543.  
  16544.   Example:
  16545.  
  16546.  
  16547.   #include "cwlmouse.h"
  16548.  
  16549.   main()
  16550.   {
  16551.  
  16552.      /* initialize mouse */
  16553.      MouseInitializeSystem();
  16554.      /* ... */
  16555.  
  16556.      /* turn off mouse */
  16557.      MouseRestoreSystem();
  16558.   }
  16559.  
  16560.  
  16561.   If you want to turn the mouse back on after calling MouseRestoreSystem(), you
  16562.   must call MouseInitializeSystem() again.
  16563.  
  16564.  
  16565.  
  16566.  
  16567.  
  16568.  
  16569.  
  16570.  
  16571.  
  16572.  
  16573.  
  16574.  
  16575.  
  16576.  
  16577.  
  16578.  
  16579.  
  16580.  
  16581.  
  16582.  
  16583.  
  16584.  Page 285                     The C Window Library                    Page 285
  16585.  
  16586.   Example:
  16587.  
  16588.   #include "cwlmouse.h"
  16589.  
  16590.   main()
  16591.   {
  16592.      int button;
  16593.      int ismouse;
  16594.      WindowInitializeSystem();
  16595.      ismouse = (MouseInitializeSystem(MOUSE_FULL_INSTALL,
  16596.                                       &button,1,1) == MOUSEFOUND));
  16597.      MoveCursor(1,1,0);
  16598.      if (ismouse)
  16599.        VideoPrintf("Mouse was found.  Number of buttons is %d\n",button);
  16600.      else
  16601.        VideoPrintf("Mouse not found");
  16602.   }
  16603.  
  16604.  
  16605.  
  16606.   Using a mouse with popup menus
  16607.   ------------------------------
  16608.  
  16609.   Once the mouse is initialized, you can use the mouse to make selections with
  16610.   popup menus.
  16611.  
  16612.   To move the highlight bar with the mouse, position the mouse cursor over any
  16613.   menu entry in the window, and hold the left mouse button down.  If the mouse
  16614.   is moved while holding the left button down, the highlight is moved along
  16615.   with the mouse cursor.  A selection is made by releasing the left mouse
  16616.   button while the mouse cursor is on an active menu entry.
  16617.  
  16618.   You can also scroll through the menu entries by placing the mouse on either a
  16619.   down arrow or up arrow symbols on the popup menu window, and then holding the
  16620.   left mouse button down.  By default, the symbols appear at the bottom border
  16621.   of the window.  If the popup window is borderless, the POPUPMOUSESCROLL
  16622.   option is ignored.
  16623.  
  16624.   To activate the mouse so that it can be used for popup menus, you must set
  16625.   the popup option POPUPMOUSE on.  If you also want to use the scroll through
  16626.   option described above, POPUPMOUSESCROLL should also be turned on.
  16627.  
  16628.  
  16629.  
  16630.  
  16631.  
  16632.  
  16633.  
  16634.  
  16635.  
  16636.  
  16637.  
  16638.  
  16639.  
  16640.  Page 286                     The C Window Library                    Page 286
  16641.  
  16642.   Example:
  16643.  
  16644.  
  16645.   #include "menu.h"
  16646.   #include "cwlmouse.h"
  16647.   int menu_func();
  16648.  
  16649.   POPUP_MENU_ENTRY menu_items[] = {
  16650.                                   " Load      F3",1,'L',F3,menu_func,
  16651.                                   " Pick  Alt-F3",2,'P',ALTF3,menu_func,
  16652.                                   " New"         ,3,'N',0,menu_func,
  16653.                                   " Save      F2",4,'S',F2,menu_func,
  16654.                                   " Write to    ",5,'W',0,menu_func,
  16655.                                   " Directory   ",6,'D',0,menu_func,
  16656.                                   " Change Dir"  ,7,'C',0,menu_func,
  16657.                                   " OS shell"    ,8,'O',0,menu_func,
  16658.                                   " Quit  Alt-X"  ,9,'Q',ALTX,menu_func,
  16659.                                   CWL_NULL,0};
  16660.   unsigned int menu_colors[5];
  16661.   POPUP_MENU_PTR p;
  16662.  
  16663.   main()
  16664.   {
  16665.     int b;
  16666.     WindowInitializeSystem();
  16667.     WindowSaveInitial(0);  /* Remember to save the initial screen */
  16668.     MouseInitiailizeSystem(MOUSE_FULL_INSTALL,&b,1,1);
  16669.    /* define colors */
  16670.     menu_colors[ENTRYCOLOR] = CREATE_VIDEO_ATTRIBUTE(white,black);
  16671.     menu_colors[BORDERCOLOR] = CREATE_VIDEO_ATTRIBUTE(white,black);
  16672.     menu_colors[HOTKEYCOLOR] = CREATE_VIDEO_ATTRIBUTE(white,blue);
  16673.     menu_colors[HIGHLIGHTCOLOR] = CREATE_VIDEO_ATTRIBUTE(cyan,black);
  16674.     menu_colors[UNAVAILCOLOR] = CREATE_VIDEO_ATTRIBUTE(white,black);
  16675.  
  16676.    /* create a POPUP_MENU_PTR */
  16677.    p = PopupCreateMenu(menu_items,menu_colors, 1,1,6,
  16678.                        POPUPSTATIC | POPUPMOUSE | POPUPMOUSESCROLL,
  16679.                        WNULLFN,VWNULLFN);
  16680.    PopupSelectMenu(p,  /* POPUP_MENU_PTR */
  16681.                      1,  /* rank of popup window */
  16682.                      1   /* menu entry to start on */
  16683.                     );
  16684.    MouseRestoreSystem();
  16685.   }
  16686.  
  16687.  
  16688.   int menu_func(POPUP_MENU_PTR p, unsigned which)
  16689.   {
  16690.     WPOINTER w;
  16691.     w = WindowInitialize(BORDER,15,15,40,4,CREATE_VIDEO_ATTRIBUTE(black,white),
  16692.                          CREATE_VIDEO_ATTRIBUTE(black,white), SINGLEBOX);
  16693.     WindowOpen(w);
  16694.     WindowClear(w);
  16695.  
  16696.  Page 287                     The C Window Library                    Page 287
  16697.  
  16698.     WindowPrintf(w,"You have selected %s",POPUP_ENTRY_STRING(p,which));
  16699.     WindowWriteCenterString(w,"Press a key to continue",3);
  16700.     WindowDisplay(w,1,NOEFFECT);
  16701.     GET_KEY();
  16702.     WindowFree(w,NOEFFECT);
  16703.     if (which == 9)
  16704.       return POPUP_EXIT;
  16705.     else
  16706.     return POPUP_CONTINUE;
  16707.   }
  16708.  
  16709.  
  16710.   The above example uses the popup menu option POPUPMOUSE and POPUPMOUSESCROLL
  16711.   options in the PopupCreateMenu() function.  Also note the call to
  16712.   MouseInitializeSystem() to initialize the mouse system.  You must use the
  16713.   constant MOUSE_FULL_INSTALL in the MouseInitializeSystem() function to make
  16714.   sure that the POPUPMOUSE and the POPUPMOUSESCROLL options will take effect.
  16715.   If a mouse does not exist, or the mouse is not activated, POPUPMOUSE and
  16716.   POPUPMOUSESCROLL will be ignored.  Also note that the include file cwlmouse.h
  16717.   was included.  These are the only changes needed for mouse support for the
  16718.   popup menus.
  16719.  
  16720.  
  16721.  
  16722.   Using a mouse with bar menus
  16723.   ----------------------------
  16724.  
  16725.   To move the highlight bar with the mouse, position the mouse cursor over any
  16726.   menu entry in the window, and hold the left mouse button down.  If the mouse
  16727.   is moved while holding the left button down, the highlight is moved along
  16728.   with the mouse cursor.  A selection is made by releasing the left mouse
  16729.   button while the mouse cursor is on an active menu entry.
  16730.  
  16731.   To activate the mouse so that it can be used for bar menus, you must set the
  16732.   bar menu option BARMOUSE on.
  16733.  
  16734.   Example:
  16735.  
  16736.   #include "menu.h"
  16737.   #include "cwlmouse.h"
  16738.  
  16739.   int menu_func();
  16740.  
  16741.   BAR_MENU_ENTRY bar_items[] = {
  16742.                                "File",1,4,'F',ALTF,menu_func,
  16743.                                "Edit",1,10,'E',0,menu_func,
  16744.                                "Run",1,17,'R',0,menu_func,
  16745.                                "Compile",1,23,'C',0,menu_func,
  16746.                                "Project",1,33,'P',0,menu_func,
  16747.                                "Options", 1,43,'O',0,menu_func,
  16748.                                "Debug",1,53,'D',0,menu_func,
  16749.                                "Break/watch",1,61,'B',0,menu_func,
  16750.                                CWL_NULL};
  16751.  
  16752.  Page 288                     The C Window Library                    Page 288
  16753.  
  16754.   unsigned int menu_colors[5];
  16755.   BAR_MENU_PTR b;
  16756.  
  16757.   main()
  16758.   {
  16759.     int b;
  16760.     WindowInitializeSystem();
  16761.     WindowSaveInitial(0);  /* Remember to save the initial screen */
  16762.     MouseInitializeSystem(MOUSE_FULL_INSTALL,&b,1,1); /* Activate mouse */
  16763.     menu_colors[ENTRYCOLOR] = CREATE_VIDEO_ATTRIBUTE(white,black);
  16764.     menu_colors[BORDERCOLOR] = CREATE_VIDEO_ATTRIBUTE(white,black);
  16765.     menu_colors[HOTKEYCOLOR] = CREATE_VIDEO_ATTRIBUTE(white,blue);
  16766.     menu_colors[HIGHLIGHTCOLOR] = CREATE_VIDEO_ATTRIBUTE(cyan,black);
  16767.     menu_colors[UNAVAILCOLOR] = CREATE_VIDEO_ATTRIBUTE(white,black);
  16768.    /* create a BAR_MENU_PTR */
  16769.     b = BarCreateMenu(bar_items,menu_colors, 1,1,
  16770.                       BARSTATIC | BARWRAP | BARMOUSE,WNULLFN);
  16771.     BarSelectMenu(b,1,1);
  16772.     MouseRestoreSystem();
  16773.   }
  16774.  
  16775.   int menu_func(BAR_MENU_PTR b, unsigned which)
  16776.   {
  16777.     WPOINTER w;
  16778.     w = WindowInitialize(BORDER,15,15,40,4,CREATE_VIDEO_ATTRIBUTE(black,white),
  16779.                          CREATE_VIDEO_ATTRIBUTE(black,white), SINGLEBOX);
  16780.     WindowOpen(w);
  16781.     WindowPrintf(w,"You have selected %s",BAR_ENTRY_STRING(b,which));
  16782.     WindowWriteCenterString(w,"Press a key to continue",3);
  16783.     WindowDisplay(w,1,NOEFFECT);
  16784.     GET_KEY();
  16785.     WindowFree(w,NOEFFECT);
  16786.     if (which == 9)
  16787.       return BAR_EXIT;
  16788.     else return BAR_CONTINUE;
  16789.   }
  16790.  
  16791.   The above example uses the bar menu option BARMOUSE option in the
  16792.   BarCreateMenu() function.  Also note the call to MouseInitializeSystem() to
  16793.   initialize the mouse system.  You must use the constant MOUSE_FULL_INSTALL in
  16794.   the MouseInitializeSystem() function to make sure that the BARMOUSE option
  16795.   will take effect.  If a mouse does not exist, or the mouse is not activated,
  16796.   BARMOUSE will be ignored.  Also note that the include file cwlmouse.h was
  16797.   included.  These are the only changes needed for mouse support for the bar
  16798.   menus.
  16799.  
  16800.  
  16801.   Using a mouse with pulldown menus
  16802.   ---------------------------------
  16803.  
  16804.   If the menu options for the mouse are turned on for all popup menus and the
  16805.   bar menu, and these menus are used as part of a pulldown menu system, the
  16806.   mouse behaves exactly the same except for the following differences:
  16807.  
  16808.  Page 289                     The C Window Library                    Page 289
  16809.  
  16810.     a) Holding the left mouse button down and positioning the mouse cursor over
  16811.        a bar menu entry will bring up the popup menu that is associated with
  16812.        the bar entry.  If there is no popup menu defined for a particular bar
  16813.        entry, releasing the mouse button will invoke the entry's function.
  16814.  
  16815.  
  16816.     b) Releasing the mouse button when it is positioned over a bar entry, and
  16817.        the bar entry has a popup associated with it, does nothing.  A general
  16818.        rule is that a menu function is only executed when the highlight bar is
  16819.        positioned on a menu entry that has a function associated with it.
  16820.  
  16821.  
  16822.   Here is a full example:
  16823.  
  16824.  
  16825.   #include "menu.h"
  16826.   #include "cwlmouse.h"
  16827.  
  16828.   #define BLACKONWHITE   CREATE_VIDEO_ATTRIBUTE(white,black)
  16829.  
  16830.  
  16831.   int menu_routine();
  16832.  
  16833.   POPUP_MENU_ENTRY menu_items1[] = {
  16834.                                     " Load      F3",1,'L',F3,menu_routine,
  16835.                                     " Pick  Alt-F3",2, 'P',ALTF3,menu_routine,
  16836.                                     " New"         ,3, 'N',0,menu_routine,
  16837.                                     " Save      F2",4, 'S',F2,menu_routine,
  16838.                                     " Write to    ",5, 'W',0,menu_routine,
  16839.                                     " Directory   ",6, 'D',0,menu_routine,
  16840.                                     " Change Dir"  ,7, 'C',0,menu_routine,
  16841.                                     " OS shell"    ,8, 'O',0,menu_routine,
  16842.                                     " Quit  Alt-X"  ,9,'Q',ALTX,menu_routine,
  16843.                                     CWL_NULL,0};
  16844.  
  16845.   POPUP_MENU_ENTRY menu_items3[] = {
  16846.                         " Run             Ctrl-F9 ",1,'R',CTRLF9,menu_routine,
  16847.                         " Program reset   Ctrl-F2 ",2,'P',CTRLF2,menu_routine,
  16848.                         " Go to Cursor         F4 ",3,'G',F4,menu_routine,
  16849.                         " Trace into           F7 ",4,'T',F7,menu_routine,
  16850.                         " Step over            F8 ",5,'S',F8,menu_routine,
  16851.                         " User screen      Alt-F5 ",6,'U',ALTF5,menu_routine,
  16852.                         CWL_NULL,0};
  16853.  
  16854.  
  16855.   POPUP_MENU_ENTRY menu_items4[] = {
  16856.           " Compile to OBJ                   ",1,'C',0,menu_routine,
  16857.           " Make EXE file                    ",2,'M',0,menu_routine,
  16858.           " Link EXE file                    ",3,'L',0,menu_routine,
  16859.           " Build all                        ",4,'B',0,menu_routine,
  16860.           " Primary C file:                  ",5,'P',0,menu_routine,
  16861.           " Get info                         ",6,'G',0,menu_routine,
  16862.             CWL_NULL,0};
  16863.  
  16864.  Page 290                     The C Window Library                    Page 290
  16865.  
  16866.   POPUP_MENU_ENTRY menu_items5[] = {
  16867.           " Project Name                     ",1,'P',0,menu_routine,
  16868.           " Break make on                    ",2,'B',0,menu_routine,
  16869.           " Auto dependencies                ",3,'A',0,menu_routine,
  16870.           " Clear project                    ",4,'C',0,menu_routine,
  16871.           " Remove messages                  ",5,'R',0,menu_routine,
  16872.             CWL_NULL,0};
  16873.  
  16874.  
  16875.   POPUP_MENU_ENTRY menu_items6[] = {
  16876.           " Compiler          ",1,'C',0,menu_routine,
  16877.           " Linker            ",2,'L',0,menu_routine,
  16878.           " Environment       ",3,'E',0,menu_routine,
  16879.           " Directories       ",4,'D',0,menu_routine,
  16880.           " Arguments         ",5,'A',0,menu_routine,
  16881.           " Save Options      ",6,'S',0,menu_routine,
  16882.           " Retrieve options  ",7,'R',0,menu_routine,
  16883.           CWL_NULL,0};
  16884.  
  16885.  
  16886.   POPUP_MENU_ENTRY menu_items7[] = {
  16887.           " Evaluate    Ctrl-F4           ",1,'E',CTRLF4,menu_routine,
  16888.           " Call Stack  Ctrl-F3           ",2,'C',CTRLF3,menu_routine,
  16889.           " Find Function                 ",3,'F',0,menu_routine,
  16890.           " Refresh display               ",4,'R',0,menu_routine,
  16891.           " Display swapping     Smart    ",5,'D',0,menu_routine,
  16892.           " Source debugging              ",6,'S',0,menu_routine,
  16893.           CWL_NULL,0};
  16894.  
  16895.  
  16896.   POPUP_MENU_ENTRY menu_items8[] = {
  16897.           " Add watch           Ctrl-F7 ",1,'A',CTRLF7,menu_routine,
  16898.           " Delete watch                ",2,'D',0,menu_routine,
  16899.           " Edit Watch                  ",3,'E',0,menu_routine,
  16900.           " Remove all watches          ",4,'R',0,menu_routine,
  16901.           " Toggle breakpoint   Ctrl-F8 ",6,'T',CTRLF8,menu_routine,
  16902.           " Clear all breakpoints       ",7,'C',0,menu_routine,
  16903.           " View next breakpoint        ",8,'V',0,menu_routine,
  16904.           CWL_NULL,0};
  16905.  
  16906.  
  16907.   BAR_MENU_ENTRY bar_items[] = {
  16908.               "File",1,4,'F',0,NULLFN,
  16909.               "Edit",1,10,'E',0,menu_routine,
  16910.               "Run",1,17,'R',0,NULLFN,
  16911.               "Compile",1,23,'C',0,NULLFN,
  16912.               "Project",1,33,'P',0,NULLFN,
  16913.               "Options", 1,43,'O',0,NULLFN,
  16914.               "Debug",1,53,'D',0,NULLFN,
  16915.               "Break/watch",1,61,'B',0,NULLFN,
  16916.                                     CWL_NULL};
  16917.  
  16918.  
  16919.  
  16920.  Page 291                     The C Window Library                    Page 291
  16921.  
  16922.   POPUP_MENU_ENTRY  *pentry[] = {menu_items1, POPUP_NULL_ENTRY,
  16923.                                  menu_items3,
  16924.                                  menu_items4, menu_items5, menu_items6,
  16925.                                  menu_items7, menu_items8};
  16926.  
  16927.   unsigned menu_colors[5];    /* Menu colors */
  16928.   BAR_MENU_PTR bar;           /* Pointer to bar menu */
  16929.   POPUP_MENU_PTR popups[8];   /* Array of pointers to popup menus */
  16930.   PULLDOWN_MENU_PTR pull;     /* Pointer to pulldown menu */
  16931.  
  16932.   WPOINTER my_open();         /* Pointer to custom bar window open function */
  16933.   unsigned int popuprank[] = {1,1,1,1,1,1,1,1};  /* Ranks of popup windows */
  16934.   int popupstart[] = {1,1,1,1,1,1,1,1}; /* Starting option for each popup
  16935.                                            menu */
  16936.   int height[] = {9,0,6,6,5,7,6,8};     /* height of each window */
  16937.  
  16938.   WPOINTER pw;  /* Misc. windows, not part of menu
  16939.                                             system */
  16940.  
  16941.   char *line =
  16942.           "─────────────────────────────"; /* Horizontal line */
  16943.  
  16944.  
  16945.   main()
  16946.   {
  16947.     int i;
  16948.     WindowInitializeSystem();
  16949.     WindowSaveInitial(0);
  16950.     MouseInitializeSystem(MOUSE_FULL_INSTALL,&b,1,1); /* Initialize mouse */
  16951.     pw = WindowInitialize(BORDER,5,10,70,5,BLACKONWHITE,BLACKONWHITE,
  16952.                           SINGLEBOX);
  16953.     WindowOpen(pw);
  16954.    /* define colors */
  16955.     menu_colors[0] = CREATE_VIDEO_ATTRIBUTE(white,black);
  16956.     menu_colors[1] = CREATE_VIDEO_ATTRIBUTE(white,black);
  16957.     menu_colors[2] = CREATE_VIDEO_ATTRIBUTE(white,blue);
  16958.     menu_colors[3] = CREATE_VIDEO_ATTRIBUTE(cyan,black);
  16959.     menu_colors[4] = CREATE_VIDEO_ATTRIBUTE(white,black);
  16960.  
  16961.     bar = BarCreateMenu(bar_items,  /* Array of BAR_MENU_ENTRY's   */
  16962.                         menu_colors,/* Pointer to menu colors      */
  16963.                         6,          /* Row to open bar menu window */
  16964.                         1,          /* Column to open bar menu window */
  16965.                         BARWRAP | BARSTATIC | BARMOUSE,
  16966.                         my_open);   /* Customized window open function */
  16967.  
  16968.                  /* Now loop to create all popup menus
  16969.           Be careful and assign NULL to the second popup menu */
  16970.  
  16971.  
  16972.  
  16973.  
  16974.  
  16975.  
  16976.  Page 292                     The C Window Library                    Page 292
  16977.  
  16978.     for (i=0; i<8; i++)       /* Loop for all popup menus */
  16979.     {
  16980.       if (pentry[i] != POPUP_NULL_ENTRY)  /* Skip over NULL popup entry */
  16981.       {
  16982.         popups[i] =
  16983.         PopupCreateMenu(pentry[i],   /* Array of POPUP_MENU_ENTRY's */
  16984.                         menu_colors, /* Array of menu colors,        */
  16985.  
  16986.                           /* The next two arguments will later be ignored */
  16987.                           1,           /* Row to open popup window on */
  16988.                           1,           /* Column to open popup */
  16989.                           height[i], /* height of the popup window   */
  16990.                                            /* No custom window open
  16991.                                               functions */
  16992.                           POPUPWRAP | POPUPSTATIC | POPUPMOUSE,
  16993.                           WNULLFN,
  16994.                           VWNULLFN);
  16995.  
  16996.               /* Now set the popup menu options */
  16997.       }
  16998.       else
  16999.         popups[i] = (POPUP_MENU_PTR)0;  /* Make this a null POPUP_MENU_PTR */
  17000.     }  /* end for (i=0 ... */
  17001.  
  17002.     VirtualWriteString(POPUP_VIRTUAL_WINDOW(popups[7]),line,5,1);
  17003.     PopupMakeEntryUnavailable(popups[6],2);   /* hide 2nd and 3rd entries in */
  17004.     PopupMakeEntryUnavailable(popups[6],3);   /* popups[6]  */
  17005.     PopupSetOptions(popups[6],POPUPOVERRIDE,1);
  17006.  
  17007.     pull = PulldownCreateMenu(popups,bar,1);
  17008.     PulldownSelectMenu(pull,1,1,popuprank,popupstart,1);
  17009.     PulldownMenuFree(pull);
  17010.     MouseRestoreSystem();
  17011.   }
  17012.  
  17013.   int menu_routine(PULLDOWN_MENU_PTR p, BAR_MENU_PTR b,
  17014.                    POPUP_MENU_PTR pop,
  17015.                    unsigned int hs, unsigned int vs)
  17016.   {
  17017.     int ch;
  17018.     WindowClear(pw);
  17019.     WindowPrintf(pw,
  17020.              "You have selected bar option %s\npopup option %s\n",
  17021.               BAR_ENTRY_STRING(b,hs),POPUP_ENTRY_STRING(pop,vs));
  17022.     WindowWriteCenterString(pw,"Press Escape to Quit",3);
  17023.     WindowWriteCenterString(pw,"Press any other key to continue...",4);
  17024.     WindowDisplay(pw,1,NOEFFECT);
  17025.     ch = GET_KEY();
  17026.     WindowHide(pw,NOEFFECT);
  17027.     if (ch == ESC)
  17028.       return PULLDOWN_EXIT;
  17029.     return PULLDOWN_CONTINUE;
  17030.   }
  17031.  
  17032.  Page 293                     The C Window Library                    Page 293
  17033.  
  17034.   WPOINTER my_open()          /* Custom window open function for bar menu */
  17035.   {
  17036.     WPOINTER w;
  17037.     w = WindowInitialize(NOBORDER,1,1,80,1,BLACKONWHITE,BLACKONWHITE,"");
  17038.     WindowOpen(w);
  17039.     return w;
  17040.   }
  17041.  
  17042.  
  17043.   Changing the mouse defaults
  17044.   ---------------------------
  17045.  
  17046.   By default, the left mouse button is held down when moving the highlight bar.
  17047.   If you prefer a different button to be used to move the highlight bar, you
  17048.   can change the button by changing the following global variables:
  17049.  
  17050.       int popmenu_button_press - holds the current button to be used to move
  17051.       the highlight bar in popup menus.
  17052.  
  17053.       int barmenu_button_press - holds the current button to be used to move
  17054.       the highlight bar in bar menus.
  17055.  
  17056.   The following constants can be assigned to these two global variables:
  17057.  
  17058.                  Constant              Definition
  17059.                  --------              ----------
  17060.                 MOUSELEFT_PRESS        Left button.
  17061.                 MOUSERIGHT_PRESS       Right button.
  17062.                 MOUSEMIDDLE_PRESS      Middle button.
  17063.  
  17064.   By default, popmenu_button_press and barmenu_button_press are assigned
  17065.   MOUSELEFT_PRESS.  Here is an example of changing these variables:
  17066.  
  17067.   #include "cwlmouse.h"
  17068.   #include "menu.h"
  17069.  
  17070.   main()
  17071.   {
  17072.        ...
  17073.  
  17074.     MouseInitializeSystem(  /* arguments */ );
  17075.     /* change mouse menu buttons */
  17076.     popmenu_button_press = MOUSERIGHT_PRESS;
  17077.     barmenu_button_press = MOUSERIGHT_PRESS;
  17078.        ...
  17079.   }
  17080.  
  17081.   The popmenu_button_press and barmenu_button_press variables are assigned
  17082.   their default values when MouseInitializeSystem() is called.  If you want to
  17083.   change these variables, make sure that the change is made after calling
  17084.   MouseInitializeSystem().
  17085.  
  17086.  
  17087.  
  17088.  Page 294                     The C Window Library                    Page 294
  17089.  
  17090.                        WINDOW AND VIRTUAL WINDOW MACROS
  17091.                        --------------------------------
  17092.  
  17093.   Note : These macros should be used after making a call to
  17094.   WindowInitializeSystem() or else unpredictable values will be returned.
  17095.  
  17096.  
  17097.   The following macros are defined in the window.h file.
  17098.   The window w is NOT CHECKED for validity.
  17099.  
  17100.  
  17101.   ISBORDER(w)    -  Returns 1 if window has a border, 0 otherwise.
  17102.  
  17103.   ISWRAP(w)      -  Returns 1 if window wrap is on, 0 otherwise.
  17104.  
  17105.   ISOPEN(w)      -  Returns 1 if window has been opened for read/write, 0
  17106.                     otherwise.
  17107.  
  17108.   ISVISIBLE(w)   -  Returns 1 if window is visible, 0 otherwise.
  17109.  
  17110.   ISVIEWPORT(w)  -  Returns 1 if window is a viewport, 0 otherwise.
  17111.  
  17112.   ISWINDOW(vw)   -  Returns 1 if virtual window has any viewports, 0 otherwise.
  17113.  
  17114.   ISBUFSAVE(w)   -  Returns 1 if text buffer for window was successfully,
  17115.                     allocated, 0 otherwise.
  17116.  
  17117.   ISSEETHRU(w)   -  Returns 1 if window is in see-thru mode, 0 otherwise.
  17118.  
  17119.   ISFROZEN(w)    -  Returns 1 if window is frozen from doing screen updates when
  17120.                     the virtual window has changed, 0 otherwise.
  17121.  
  17122.   ISSHADOW(w)    -  Returns 1 if the window has a shadow, 0 otherwise.
  17123.  
  17124.   ISSHADOWTRANS(w) - Returns 1 if the shadow is transparent, 0 otherwise.
  17125.  
  17126.   SHADOW_POS(w) -   Returns the position of the shadow as an integer.  The valid
  17127.                     positions are as follows:
  17128.  
  17129.                      Shadow Position                Return Value
  17130.                      ---------------                ------------
  17131.                        SHADOWUPLEFT                       1
  17132.                        SHADOWUPRIGHT                      2
  17133.                        SHADOWLOWLEFT                      3
  17134.                        SHADOWLOWRIGHT                     4
  17135.  
  17136.                      If there is no shadow, a 0 is returned.
  17137.  
  17138.   SHADOW_CHAR(w) -  Returns the current character used to draw the window's
  17139.                     shadow.  Return value is undefined if the window has no
  17140.                     shadow.
  17141.  
  17142.  
  17143.  
  17144.  Page 295                     The C Window Library                    Page 295
  17145.  
  17146.   SHADOW_ATTR(w) -  Returns the current video attribute used to draw the
  17147.                     window's shadow.  Return value is undefined if the window
  17148.                     has no shadow
  17149.  
  17150.   SHADOW_WIDTH(w) - Returns the width of the window's shadow.  Return value is
  17151.                     undefined if the window has no shadow.
  17152.  
  17153.   SHADOW_HEIGHT(w) - Returns the height of the window's shadow.  Return value is
  17154.                      undefined if the window has no shadow.
  17155.  
  17156.  
  17157.   VIRTUAL_ATTRIBUTE_ON(vw) - Returns 1 if the virtual window vw is attributed,
  17158.                              0 otherwise.
  17159.  
  17160.   VIRTUAL_WINDOW_EXIST(vw) - Returns 1 if virtual window was
  17161.                              initialized, 0 otherwise.
  17162.  
  17163.   VIRTUAL_HEIGHT(vw) - Returns the number of rows in a virtual window vw.
  17164.  
  17165.  
  17166.   VIRTUAL_WIDTH(vw) - Returns the number of columns in a virtual window.
  17167.  
  17168.  
  17169.   VIRTUAL_WINDOW(w) - Returns the virtual window that the viewport w is currently
  17170.                       viewing.
  17171.  
  17172.   VIEWPORT_ROW(w) - Returns the upper left row of where the viewport w is
  17173.                     positioned on the virtual window.
  17174.  
  17175.   VIEWPORT_COLUMN(w) - Returns the upper left column of where the viewport w is
  17176.                        positioned on the virtual window.
  17177.  
  17178.   VIRTUAL_COORD_IN_VIEWPORT(w,row,col) - Returns 1 if the virtual window
  17179.                                          coordinates (row,col) are inside the
  17180.                                          viewport w, 0 otherwise.  The virtual
  17181.                                          window must have w as a viewport.
  17182.  
  17183.   WINDOW_BORDER_CHARS(w) - Returns the current border of a window as a string.
  17184.  
  17185.  
  17186.   WINDOW_BORDER_COLOR(w) - Returns the border color of the window w.
  17187.  
  17188.  
  17189.   WINDOW_COLUMN(w) - Returns the absolute column of the upper left hand corner
  17190.                      of the window.
  17191.  
  17192.   WINDOW_EXIST(w)  - Returns 1 if window was initialized, 0 otherwise.
  17193.  
  17194.   WINDOW_HEIGHT(w) - Returns the height of the text area of the window w.
  17195.  
  17196.  
  17197.   WINDOW_PAGENUM(w) - Returns the video page of where the window will be
  17198.                       displayed.
  17199.  
  17200.  Page 296                     The C Window Library                    Page 296
  17201.  
  17202.   WINDOW_RANK(w) - Returns the rank of the window w.
  17203.  
  17204.  
  17205.   WINDOW_ROW(w) - Returns the absolute row coordinate of the upper left hand
  17206.                   corner of the window w.
  17207.  
  17208.  
  17209.  
  17210.  
  17211.  
  17212.  
  17213.  
  17214.  
  17215.  
  17216.  
  17217.  
  17218.  
  17219.  
  17220.  
  17221.  
  17222.  
  17223.  
  17224.  
  17225.  
  17226.  
  17227.  
  17228.  
  17229.  
  17230.  
  17231.  
  17232.  
  17233.  
  17234.  
  17235.  
  17236.  
  17237.  
  17238.  
  17239.  
  17240.  
  17241.  
  17242.  
  17243.  
  17244.  
  17245.  
  17246.  
  17247.  
  17248.  
  17249.  
  17250.  
  17251.  
  17252.  
  17253.  
  17254.  
  17255.  
  17256.  Page 297                     The C Window Library                    Page 297
  17257.  
  17258.                                   MENU MACROS
  17259.                                   -----------
  17260.  
  17261.   The following macros are defined in the header file menu.h.
  17262.  
  17263.  
  17264.   Popup Menu Macros
  17265.   -----------------
  17266.  
  17267.   POPUP_CONFIRM_ON(p) - Returns 1 if the POPUP_MENU_PTR p has the confirmation
  17268.                         for hotkey selections on, 0 otherwise.
  17269.  
  17270.   POPUP_DISPLAY_ON(p) - Returns 1 if the POPUP_MENU_PTR p's window is to be
  17271.                         displayed regardless if the menu manager has returned
  17272.                         to the calling function, 0 otherwise.
  17273.  
  17274.   POPUP_ENHANCED_ON(p) - Returns 1 if the popup menu will recognize enhanced
  17275.                          keys, 0 otherwise.
  17276.  
  17277.   POPUP_ENTRY_STRING(p,entry) - Returns the entry string of POPUP_MENU_ENTRY
  17278.                                 entry.
  17279.  
  17280.   POPUP_EXPLODE(p) -    Returns the special effect constant of the
  17281.                         POPUP_MENU_PTR p.  This special effect is used to hide,
  17282.                         close, and open the popup menu's window.
  17283.  
  17284.   POPUP_MOUSE_ON(p) -   Returns 1 if a mouse can be used to make selections, 0
  17285.                         otherwise.
  17286.  
  17287.   POPUP_MOUSE_SCROLL_ON(p) - Returns 1 if a mouse can be used to scroll through
  17288.                              the entries if the entries cannot fit in the popup
  17289.                              window, 0 otherwise.
  17290.  
  17291.   POPUP_NUMBER_OF_ENTRIES(p) - Returns the total number of entries defined in
  17292.                                the POPUP_MENU_PTR p.
  17293.  
  17294.   POPUP_OVERRIDE_ON(p) - Returns 1 if POPUP_MENU_PTR p will have unavailable
  17295.                          options processed, 0 otherwise.
  17296.  
  17297.   POPUP_PULLDOWN_ON(p) - Returns 1 if the POPUP_MENU_PTR p is incorporated in a
  17298.                          pulldown menu system, 0 otherwise.
  17299.  
  17300.   POPUP_STATIC_ON(p) -  Returns 1 if the POPUP_MENU_PTR p will remain on the
  17301.                         screen when an entry is selected, 0 otherwise.
  17302.  
  17303.   POPUP_STRING_IN_WINDOW(p,entry) - Returns 1 if the POPUP_MENU_PTR p has entry
  17304.                                     number entry displayed in the popup menu's
  17305.                                     window, 0 otherwise.  This macro is useful
  17306.                                     if you have a scrolling popup menu and want
  17307.                                     to know if a particular entry is displayed
  17308.                                     in the window.
  17309.  
  17310.   POPUP_VIRTUAL_WINDOW(p) - Returns the VWPOINTER of the popup menu.
  17311.  
  17312.  Page 298                     The C Window Library                    Page 298
  17313.  
  17314.   POPUP_WINDOW(p) - Returns the WPOINTER of the popup menu.
  17315.  
  17316.   POPUP_WRAP_ON(p) -    Returns 1 if the highlight wrap of POPUP_MENU_PTR p is
  17317.                         on, otherwise 0.
  17318.  
  17319.  
  17320.  
  17321.   Bar Menu Macros
  17322.   ---------------
  17323.  
  17324.   BAR_CONFIRM_ON(b) - Returns 1 if the BAR_MENU_PTR b has the confirmation for
  17325.                       hotkey selections on, 0 otherwise.
  17326.  
  17327.   BAR_DISPLAY_ON(b) - Returns 1 if the BAR_MENU_PTR b's window is to be
  17328.                       displayed regardless if the menu manager has returned to
  17329.                       the calling function, 0 otherwise.
  17330.  
  17331.   BAR_ENHANCED_ON(p) - Returns 1 if the bar menu will recognize enhanced keys,
  17332.                        0 otherwise.
  17333.  
  17334.   BAR_ENTRY_AVAILABLE(b,entry) - Returns 1 if the BAR_MENU_ENTRY entry is
  17335.                                  available, 0 otherwise.
  17336.  
  17337.   BAR_ENTRY_STRING(b,entry) - Returns the entry string of BAR_MENU_ENTRY entry.
  17338.  
  17339.   BAR_EXPLODE(b) -  Returns the special effect constant of the BAR_MENU_PTR b.
  17340.                     This special effect is used to hide, close, and open the
  17341.                     popup menu's window.
  17342.  
  17343.   BAR_NUMBER_OF_ENTRIES(b) - Returns the total number of entries defined in
  17344.                              the BAR_MENU_PTR b.
  17345.  
  17346.   BAR_OVERRIDE_ON(b) - Returns 1 if BAR_MENU_PTR b will have unavailable
  17347.                        options processed, 0 otherwise.
  17348.  
  17349.   BAR_PULLDOWN_ON(b) - Returns 1 if the BAR_MENU_PTR b is incorporated in a
  17350.                        pulldown menu system, 0 otherwise.
  17351.  
  17352.   BAR_STATIC_ON(b) -  Returns 1 if the BAR_MENU_PTR b will remain on the screen
  17353.                       when an entry is selected, 0 otherwise.
  17354.  
  17355.   BAR_WINDOW(b) - Returns the WPOINTER of the bar menu.
  17356.  
  17357.   BAR_WRAP_ON(b) -    Returns 1 if the highlight wrap of BAR_MENU_PTR b is on,
  17358.                       otherwise 0.
  17359.  
  17360.  
  17361.  
  17362.  
  17363.  
  17364.  
  17365.  
  17366.  
  17367.  
  17368.  Page 299                     The C Window Library                    Page 299
  17369.  
  17370.   Pulldown Menu Macros
  17371.   --------------------
  17372.  
  17373.   BAR_MENU_PTR_FROM_POPUP(pop) - Returns the BAR_MENU_PTR associated with the
  17374.                                  POPUP_MENU_PTR pop, which must be part of a
  17375.                                  pulldown menu system.
  17376.  
  17377.   BAR_MENU_PTR_FROM_PULLDOWN(pull) - Returns the BAR_MENU_PTR assocated with
  17378.                                      the PULLDOWN_MENU_PTR pull.
  17379.  
  17380.   POPUP_MENU_PTR_FROM_BAR(b,entry) -
  17381.                       Returns the POPUP_MENU_PTR associated with the
  17382.                       BAR_MENU_PTR b.  The entry argument is the number of the
  17383.                       POPUP_MENU_PTR desired in the pulldown menu system.  For
  17384.                       example, if you want to know the first POPUP_MENU_PTR
  17385.                       given only a BAR_MENU_PTR, the call to this macro would
  17386.                       be POPUP_MENU_PTR_FROM_BAR(b,1).
  17387.  
  17388.   POPUP_MENU_PTR_FROM_PULLDOWN(pull,entry) -
  17389.                       Returns the POPUP_MENU_PTR associated with the
  17390.                       PULLDOWN_MENU_PTR pull.  The entry is the number of the
  17391.                       desired POPUP_MENU_PTR desired in the pulldown menu
  17392.                       system.
  17393.  
  17394.   PULLDOWN_MENU_PTR_FROM_BAR(b) - Returns the PULLDOWN_MENU_PTR associated with
  17395.                                   the bar menu b.
  17396.  
  17397.  
  17398.   PULLDOWN_MENU_PTR_FROM_POPUP(pop) - Returns the PULLDOWN_MENU_PTR associated
  17399.                                       with the POPUP_MENU_PTR pop.
  17400.  
  17401.  
  17402.  
  17403.  
  17404.  
  17405.  
  17406.  
  17407.  
  17408.  
  17409.  
  17410.  
  17411.  
  17412.  
  17413.  
  17414.  
  17415.  
  17416.  
  17417.  
  17418.  
  17419.  
  17420.  
  17421.  
  17422.  
  17423.  
  17424.  Page 300                     The C Window Library                    Page 300
  17425.  
  17426.                                  VIDEO MACROS
  17427.                                  ------------
  17428.  
  17429.   The following macros are defined in the vidsys.h file.
  17430.   Note:  by including window.h in your source files, vidsys.h is automatically
  17431.   included.
  17432.  
  17433.   CHECK_SNOW - Returns 1 if during direct screen writes that video "snow" is
  17434.                eliminated.  You can also assign values to this macro.  This
  17435.                macro is a pseudonym for the variable chksnow_.
  17436.  
  17437.                Example:
  17438.                 #include "vidsys.h"
  17439.                     ...
  17440.                 int a;
  17441.                 a = CHECK_SNOW;  /* Returns 1 if snow checking on,
  17442.                                     0 otherwise */
  17443.                 CHECK_SNOW = 0;  /* Turn off snow checking */
  17444.  
  17445.   CREATE_VIDEO_ATTRIBUTE(bg,fg) - creates a video attribute using bg as the
  17446.                   background color, and fg as the foreground color.  The
  17447.                   following variables can be used:
  17448.  
  17449.       Variable                     |    Variable
  17450.         Name       Color    Value  |     Name           Color          Value
  17451.       -------      -----    -----  |    -------         -----          -----
  17452.         black      Black      0    |    gray            Gray             8
  17453.         blue       Blue       1    |    lightblue       Light Blue       9
  17454.         green      Green      2    |    lightgreen      Light green     10
  17455.         cyan       Cyan       3    |    lightcyan       Light cyan      11
  17456.         red        Red        4    |    lightred        Light red       12
  17457.         magenta    Magenta    5    |    lightmagenta    Light magenta   13
  17458.         brown      Brown      6    |    yellow          Yellow          14
  17459.         white      White      7    |    lightwhite      Intense white   15
  17460.  
  17461.  
  17462.   The variables above are initialized when WindowInitializeSystem() is called.
  17463.   If you want to use a color value before WindowInitializeSystem() is called,
  17464.   you can use the uppercase equivalent of the above variables, with a trailing
  17465.   underscore character attached to the name.  For example BLACK_ would be used
  17466.   instead of black, WHITE_ would be used instead of white, etc.  For monochrome
  17467.   systems, the only colors that are available are black, white, and intense
  17468.   white.  An attribute of blue creates an underline attribute, and light blue
  17469.   creates an intense underlined attribute.  Any other combination on a
  17470.   monochrome system is undefined.
  17471.  
  17472.  
  17473.   GET_BGROUND_COLOR(c) - Returns the background color of the video attribute c.
  17474.  
  17475.   GET_FGROUND_COLOR(c) - Returns the foreground color of the video attribute c.
  17476.  
  17477.   GET_OFFSET(x) -  Returns the offset of a pointer x.  The pointer can be either
  17478.                    near or far.
  17479.  
  17480.  Page 301                     The C Window Library                    Page 301
  17481.  
  17482.   GET_SEGMENT(x) - Returns the segment address of a pointer x.  The pointer can
  17483.                    be either near or far.
  17484.  
  17485.   MAKE_FAR_POINTER(a,b) - Creates a far pointer made up of segment address a,
  17486.                           and offset address b.
  17487.  
  17488.   SCREEN_OFFSET(r,c,a) -  Returns the screen offset of the address of a
  17489.                           character located at row r and column c of the video
  17490.                           page a.  The screen segment is defined in the macro
  17491.                           SCREEN_SEGMENT.  both r and c should be >= 1.
  17492.            Example:
  17493.                char far *p;
  17494.                p = MAKE_FAR_POINTER(SCREEN_SEGMENT,SCREEN_OFFSET(1,1,0));
  17495.  
  17496.            The above example has created a far pointer p that points to the
  17497.            screen buffer memory at row 1, column 1, on video page 0.
  17498.  
  17499.   SCREEN_OFFSET_ATTR(r,c,a) - Returns the screen offset of the address of a
  17500.                        attribute located at row r and column c of the video page
  17501.                        a.  The screen segment is defined in the macro
  17502.                        SCREEN_SEGMENT. both r and c should be >= 1.
  17503.  
  17504.   SCREEN_SEGMENT - Returns the screen segment of video page 0.  This macro is a
  17505.                    pseudonym for the variable scrnseg_.
  17506.  
  17507.  
  17508.   SCREEN_WRITE_METHOD - Returns 1 if writing directly to the screen, 0 if using
  17509.                         the BIOS.  You can also use this macro to assign the
  17510.                         particular writing method.  This macro controls the way
  17511.                         The C Window Library will do screen updates.  The
  17512.                         default is 1 (write directly to screen).
  17513.          Example:
  17514.              #include "vidsys.h"
  17515.              int a,b;
  17516.              a = SCREEN_WRITE_METHOD;  /* a now has the current write method */
  17517.              SCREEN_WRITE_METHOD = 1;  /* set write method to direct screen
  17518.                                           memory */
  17519.  
  17520.              This macro is a pseudonym for the variable scrnwrt_flag which is a
  17521.              member of the SYS_FLAGS structure video_system_flags.
  17522.  
  17523.  
  17524.   VIDEO_PAGESIZE - Returns the size (in bytes) of a video page.  You can also
  17525.                    assign values to VIDEO_PAGESIZE, but the best thing to do is
  17526.                    to leave it alone unless you are familiar with the video
  17527.                    system you are using.  This macro is a pseudonym for the
  17528.                    variable pagesize_.
  17529.  
  17530.                    Example:
  17531.                    #include "vidsys.h"
  17532.                    int psize;
  17533.                    psize = VIDEO_PAGESIZE; /* Return the current
  17534.                                                video page size */
  17535.  
  17536.  Page 302                     The C Window Library                    Page 302
  17537.  
  17538.   The following macros are used to identify the monitor type and video card
  17539.   being used in the system.
  17540.   Note :  These macros are pseudonyms for members in the SYS_FLAGS structure
  17541.           called video_system_flags.
  17542.  
  17543.  
  17544.    CGA_ACTIVE    -   Returns 1 if Color Graphics Adapter is active, 0 otherwise.
  17545.    EGA_ACTIVE    -   Returns 1 if EGA is active, 0 otherwise.
  17546.    EGA_COLOR_ATTACHED - Returns 1 if monitor hooked up to EGA is a high
  17547.                         resolution color monitor, 0 otherwise.
  17548.    EGA_COLOR_ON  - Returns 1 if EGA is in color mode, 0 otherwise.
  17549.    EGA_INSTALLED - Returns 1 if EGA is installed, 0 otherwise.
  17550.    HERCULES_ACTIVE - Returns 1 if Hercules adapter is active, 0 otherwise.
  17551.    MCGA_ACTIVE    - Returns 1 if the MCGA is the active video card.
  17552.    MCGA_COLOR_ON - Returns 1 if MCGA is in color mode, 0 otherwise.
  17553.    MCGA_INSTALLED - Returns 1 if MCGA is installed (IBM PS/2 Model 30),
  17554.                     0 otherwise.
  17555.    MDA_ACTIVE    -   Returns 1 if MDA (Monochrome) adapter is active,
  17556.                      0 otherwise.
  17557.    MONO_MODE_ON  -   Returns 1 if Monochrome mode is on regardless of the
  17558.                      adapter, 0 otherwise.
  17559.    VGA_ACTIVE    -   Returns 1 if VGA is active adapter, 0 otherwise.
  17560.    VGA_COLOR_ATTACHED - Returns 1 if monitor hooked up to VGA is analog color,
  17561.                         0 otherwise.
  17562.    VGA_COLOR_ON  -   Returns 1 if VGA is in color mode, 0 otherwise.
  17563.    VGA_INSTALLED -   Returns 1 if VGA Adapter is installed, 0 otherwise.
  17564.  
  17565.  
  17566.    You should always check the ..._ACTIVE constants before checking for other
  17567.    aspects of the video system.  For example, make sure that VGA_ACTIVE returns
  17568.    1 before checking any other VGA_... macro.  If VGA_ACTIVE is 1, then all
  17569.    VGA_... macros are valid.  The same thing goes for EGA.  MONO_MODE_ON is the
  17570.    only macro that can be tested regardless of the video adapter.
  17571.  
  17572.    The following are macros defined in version 1.0 of The C Window Library,
  17573.    which are still supported:
  17574.  
  17575.    CGA_MODE_ON  - Same as CGA_ACTIVE.
  17576.    EGA_MODE_ON  - Same as EGA_ACTIVE.
  17577.    VGA_MODE_ON  - Same as VGA_ACTIVE.
  17578.    MCGA_MODE_ON - Same as MCGA_ACTIVE.
  17579.    EGA_MONO_ON  - Returns 1 if EGA is in mono mode.
  17580.    VGA_MONO_ON  - Returns 1 if VGA is in mono mode.
  17581.    MCGA_MONO_ON - Returns 1 if MCGA is in mono mode.
  17582.  
  17583.    You should not assign values to the above pseudo-constants unless you are
  17584.    completely familiar with The C Window Library's internal functions.
  17585.  
  17586.    LINEMODE25 - Returns 1 if screen displays 25 lines, 0 otherwise.
  17587.    LINEMODE43 - Returns 1 if screen displays 43 lines (EGA and VGA), 0
  17588.                 otherwise.
  17589.    LINEMODE50 - Returns 1 if screen displays 50 lines (VGA), 0 otherwise.
  17590.  
  17591.  
  17592.  
  17593.  Page 303                     The C Window Library                    Page 303
  17594.  
  17595.                                   BOX MACROS
  17596.                                   ----------
  17597.  
  17598.  
  17599.    The list of defined box drawing macros is as follows:
  17600.  
  17601.                           DOUBLEBOX
  17602.                           SINGLEBOX
  17603.                           MIXEDBOX1
  17604.                           MIXEDBOX2
  17605.                           HATCHBOX1
  17606.                           HATCHBOX2
  17607.                           HATCHBOX3
  17608.                           SOLIDBOX1
  17609.                           SOLIDBOX2
  17610.                           BLANKBOX
  17611.                           DOTTEDLINE
  17612.  
  17613.    Each one of these macros are 8 character strings that can be used in
  17614.    functions that call for a string of box drawing characters.
  17615.  
  17616.  
  17617.  
  17618.  
  17619.  
  17620.  
  17621.  
  17622.  
  17623.  
  17624.  
  17625.  
  17626.  
  17627.  
  17628.  
  17629.  
  17630.  
  17631.  
  17632.  
  17633.  
  17634.  
  17635.  
  17636.  
  17637.  
  17638.  
  17639.  
  17640.  
  17641.  
  17642.  
  17643.  
  17644.  
  17645.  
  17646.  
  17647.  
  17648.  
  17649.  Page 304                     The C Window Library                    Page 304
  17650.  
  17651.                                EXPLOSION MACROS
  17652.                                ----------------
  17653.  
  17654.    The list of explosion constants is as follows:
  17655.  
  17656.                           NOEFFECT
  17657.                           EXPLODE
  17658.                           CONTRACT
  17659.                           BRICKS
  17660.                           MIDDLEROWOUT
  17661.                           TOPBOTTOMIN
  17662.                           TOPDOWN
  17663.                           BOTTOMUP
  17664.                           MIDDLECOLOUT
  17665.                           LEFTRIGHTIN
  17666.                           LEFTTORIGHT
  17667.                           RIGHTTOLEFT
  17668.  
  17669.  
  17670.  
  17671.  
  17672.  
  17673.  
  17674.  
  17675.  
  17676.  
  17677.  
  17678.  
  17679.  
  17680.  
  17681.  
  17682.  
  17683.  
  17684.  
  17685.  
  17686.  
  17687.  
  17688.  
  17689.  
  17690.  
  17691.  
  17692.  
  17693.  
  17694.  
  17695.  
  17696.  
  17697.  
  17698.  
  17699.  
  17700.  
  17701.  
  17702.  
  17703.  
  17704.  
  17705.  Page 305                     The C Window Library                    Page 305
  17706.  
  17707.                                  KEYBOARD MACROS
  17708.                                  ---------------
  17709.  
  17710.   The following macros are used to get characters from the keyboard.
  17711.   They are prototyped in the file key.h.
  17712.  
  17713.  
  17714.   ENHANCED_KEYBOARD() - Returns 1 if there is an enhanced keyboard attached, 0
  17715.                         otherwise.
  17716.  
  17717.   FLUSH_KEYBOARD() - Flushes the keyboard buffer.
  17718.  
  17719.   GET_KEY() - Returns what key was pressed either as a character, or as a
  17720.               scan code if a non-ascii key is pressed.  A list of scan codes are
  17721.               found in the file keycodes.h.
  17722.  
  17723.   GET_ENHANCED_KEY() - Same as GET_KEY() except that keys on the enhanced
  17724.                        keyboards are distinguishable.  For instance, the  key on
  17725.                        the keypad will return a different scan code than the
  17726.                        Home key on the separate cursor movement pad.
  17727.  
  17728.   GET_SHIFT_STATE() - Returns the shift state of the keyboard.  The shift state
  17729.                       tells whether the Alt, Ctrl or Shift key was pressed, or
  17730.                       if the Num Lock, Scroll Lock, or Caps Lock keys are on or
  17731.                       off.  The shift state is updated after each call to
  17732.                       GET_KEY() or GET_ENHANCED_KEY().  Use a bitwise AND (&)
  17733.                       when testing for these keys, as the example below
  17734.                       demonstrates:
  17735.  
  17736.                       Example:
  17737.  
  17738.                       #include "key.h"
  17739.                       #include "keycodes.h"
  17740.  
  17741.                          ...
  17742.                       int CurrentShift;
  17743.                       GET_KEY();
  17744.                       CurrentShift = GET_SHIFT_STATE() & ALT;
  17745.  
  17746.                       printf("The Alt key was %s pressed",
  17747.                       CurrentShift?"":"not");
  17748.  
  17749.   ISKEYREADY() - Returns 1 if there is a key ready in the keyboard buffer, 0
  17750.                   otherwise.
  17751.  
  17752.  
  17753.  
  17754.  
  17755.  
  17756.  
  17757.  
  17758.  
  17759.  
  17760.  
  17761.  Page 306                     The C Window Library                    Page 306
  17762.  
  17763.   Keyboard Idle function
  17764.   ----------------------
  17765.  
  17766.   When calling the GET_KEY() or GET_ENHANCED_KEY() macros, you can call a
  17767.   function while the program is waiting for a key to be pressed.  The global
  17768.   variable key_idle_func is a function pointer that points to this function.
  17769.   Here is the prototype:
  17770.  
  17771.                    void (*key_idle_func)(void)
  17772.  
  17773.   There are no arguments and no return value to this function.  You must
  17774.   initialize this function pointer after you have called
  17775.   WindowInitializeSystem().  If not, the function you assigned will not be
  17776.   executed.  Here is an example:
  17777.  
  17778.  
  17779.   #include "window.h"
  17780.   #define NORM  CREATE_VIDEO_ATTRIBUTE(black,white)
  17781.   void count_numbers(void);
  17782.   int num = 0;
  17783.  
  17784.   main()
  17785.   {
  17786.     WindowInitializeSystem();
  17787.     key_idle_func = count_numbers;
  17788.     ClearScreen(NORM);
  17789.     GET_KEY();
  17790.     MoveCursor(2,1,0);
  17791.     VideoPrintf("You stopped the count at %d",num);
  17792.   }
  17793.  
  17794.   void count_numbers()
  17795.   {
  17796.     num++;
  17797.     MoveCursor(1,1,0);
  17798.     VideoPrintf("%d",num);
  17799.     delay(1000);
  17800.   }
  17801.  
  17802.  
  17803.   The program above keeps a counter going in the upper left hand corner of the
  17804.   screen until a key is pressed.
  17805.  
  17806.   If you want to unassign the key_idle_func function pointer, do the
  17807.   following:
  17808.  
  17809.                key_idle_func = VOIDNULLFN;
  17810.  
  17811.   This function can perform just about anything.  One major use would be to
  17812.   update an on screen clock while the keyboard is not being used.
  17813.  
  17814.  
  17815.  
  17816.  
  17817.  
  17818.  Page 307                     The C Window Library                    Page 307
  17819.  
  17820.   Keyboard Intercept function
  17821.   ---------------------------
  17822.  
  17823.   Before GET_KEY() and GET_ENHANCED_KEY() return a value, you can intercept the
  17824.   pending return value, examine it, and change the value to whatever you wish.
  17825.   This is good if you want to reassign keys easily.  The function pointer to
  17826.   assign is key_intercept_func.  Here is the prototype:
  17827.  
  17828.            unsigned (*key_intercept_func)(int which, unsigned keyval)
  17829.  
  17830.   The first argument is an integer that denotes whether a mouse button was
  17831.   pressed, or a key from the keyboard was pressed.  If a keyboard key was
  17832.   pressed, the value of which is equal to KEYPRESSED, otherwise it is
  17833.   MOUSEPRESSED.  If you do not have a mouse, or the mouse is not activated,
  17834.   this value will always be KEYPRESSED.  More information on the mouse in the
  17835.   USING THE MOUSE section in the manual.  The return value will be the new key
  17836.   value that GET_KEY() and GET_ENHANCED_KEY() will return.  It is advisable to
  17837.   use the key codes described in "keycodes.h" if you are returning a non-ascii
  17838.   key.  Here is an example:
  17839.  
  17840.   #include "window.h"
  17841.   #define NORM  CREATE_VIDEO_ATTRIBUTE(black,white)
  17842.   unsigned switch_to_quotes(int,unsigned);
  17843.   unsigned oldchar;
  17844.  
  17845.   main()
  17846.   {
  17847.     int ch;
  17848.     WindowInitializeSystem();
  17849.     key_intercept_func = switch_to_quotes;
  17850.     ClearScreen(NORM);
  17851.     ch = GET_KEY();
  17852.     MoveCursor(1,1,0);
  17853.     VideoPrintf("The old key was %c.  The new code is %c",oldchar,ch);
  17854.   }
  17855.  
  17856.   unsigned switch_to_quotes(int which, unsigned keyval)
  17857.   {
  17858.     if (which == KEYPRESSED)
  17859.     {
  17860.       oldchar = keyval;
  17861.       return (unsigned)'"';  /* return a double quote */
  17862.     }
  17863.   }
  17864.  
  17865.   The program above intercepts the return value of GET_KEY() and assigns the
  17866.   double quote character.  The character is then printed out on the screen
  17867.   along with the character that was assigned.
  17868.  
  17869.   If you want to unassign the key_intercept_func function pointer, do the
  17870.   following:
  17871.  
  17872.                key_intercept_func = NULLFN;
  17873.  
  17874.  Page 308                     The C Window Library                    Page 308
  17875.  
  17876.                                  CURSOR MACROS
  17877.                                  -------------
  17878.  
  17879.  
  17880.   The following macros are used for cursor manipulation.
  17881.  
  17882.  
  17883.   CREATE_CURSOR_SHAPE(startline, endline) - Forms an integer quantity
  17884.                       representing a cursor with a starting scan line of
  17885.                       scanline, and an ending scan line of endline.
  17886.  
  17887.   THIN - constant for a thin (underline) cursor.
  17888.  
  17889.   BLOCK - constant for a block (fat) cursor.
  17890.  
  17891.   INVISIBLE - constant for a hidden cursor.
  17892.  
  17893.  
  17894.  
  17895.  
  17896.  
  17897.  
  17898.  
  17899.  
  17900.  
  17901.  
  17902.  
  17903.  
  17904.  
  17905.  
  17906.  
  17907.  
  17908.  
  17909.  
  17910.  
  17911.  
  17912.  
  17913.  
  17914.  
  17915.  
  17916.  
  17917.  
  17918.  
  17919.  
  17920.  
  17921.  
  17922.  
  17923.  
  17924.  
  17925.  
  17926.  
  17927.  
  17928.  
  17929.  
  17930.  Page 309                     The C Window Library                    Page 309
  17931.  
  17932.                       IMPORTANT GLOBAL VARIABLES
  17933.                       --------------------------
  17934.  
  17935.   There are global variables that you should be aware of in The C Window
  17936.   Library.  Most of these variables can be changed, while others should be left
  17937.   alone.  You must call WindowInitializeSystem() before modifying any of these
  17938.   variables.
  17939.  
  17940.   When describing the global variable, the following scheme is used:
  17941.  
  17942.  
  17943.  
  17944.  
  17945.  
  17946.   Variable         variable name
  17947.  
  17948.   Defined in       XXXXXX.h  (file where variable is declared)
  17949.  
  17950.   Initialized in   function call (function where variable gets its initial
  17951.                                   value)
  17952.  
  17953.   Purpose          Description of variable's purpose.
  17954.  
  17955.   Default Value    default value for variable.
  17956.  
  17957.   Modify Info      Tells if variable should be modified.
  17958.  
  17959.  
  17960.  
  17961.   These variables are described in alphabetical order.
  17962.  
  17963.  
  17964.  
  17965.  
  17966.  
  17967.  
  17968.  
  17969.   Variable         int active_video_page
  17970.  
  17971.   Defined in       vidsys.h
  17972.  
  17973.   Initialized in   WindowInitializeSystem()
  17974.  
  17975.   Purpose          Current active video page.
  17976.  
  17977.   Modify Info      Should be modified only by calling the SetActiveVideoPage()
  17978.                    function.
  17979.  
  17980.  
  17981.  
  17982.  
  17983.  
  17984.  
  17985.  
  17986.  Page 310                     The C Window Library                    Page 310
  17987.  
  17988.   Variable         int barmenu_button_press
  17989.  
  17990.   Defined in       cwlmouse.h
  17991.  
  17992.   Initialized in   MouseInitializeSystem()
  17993.  
  17994.   Purpose          Holds the current button mouse button to press to move the
  17995.                    highlight bar on bar menus.
  17996.  
  17997.   Default Value    MOUSELEFT_PRESS.
  17998.  
  17999.   Modify Info      Can be modified at any time.
  18000.  
  18001.  
  18002.  
  18003.  
  18004.  
  18005.   Variable         int caldelay_
  18006.  
  18007.   Defined          vidsys.h
  18008.  
  18009.   Initialized in   WindowInitializeSystem()
  18010.  
  18011.   Purpose          This is a calibration count for the delay() function.
  18012.  
  18013.   Modify Info      Should only be modified if the delay() function is giving
  18014.                    inaccurate delay times.  If the delay is too long, then
  18015.                    caldelay_ should be decreased.  If it is too short, then
  18016.                    caldelay_ should be increased.
  18017.  
  18018.  
  18019.  
  18020.  
  18021.   Variable         int check_existence_flag
  18022.  
  18023.   Defined in       window.h
  18024.  
  18025.   Initialized in   WindowInitializeSystem()
  18026.  
  18027.   Purpose          Informs The C Window Library to check for window, virtual
  18028.                    window, and for non-open window errors.  If this variable is
  18029.                    1, the library routines will check for these conditions.  If
  18030.                    0, these conditions are not checked.
  18031.  
  18032.   Default Value    1.
  18033.  
  18034.   Modify Info      Can be modified at any time, but is recommended that this
  18035.                    flag be left on for development work.  Make sure that your
  18036.                    application program is stable if you plan to turn off
  18037.                    checking.
  18038.  
  18039.  
  18040.  
  18041.  
  18042.  Page 311                     The C Window Library                    Page 311
  18043.  
  18044.   Variable         int chksnow_
  18045.  
  18046.   Defined          vidsys.h
  18047.  
  18048.   Initialized in   WindowInitializeSystem()
  18049.  
  18050.   Purpose          This variable controls whether the display should be checked
  18051.                    for snow when writing directly to the screen.  A value of
  18052.                    1 will check for snow, while a value of 0 will turn off
  18053.                    snow checking.
  18054.  
  18055.   Default Value    0 (no snow checking).
  18056.  
  18057.   Modify Info      Can be modified at any time.
  18058.  
  18059.  
  18060.  
  18061.  
  18062.  
  18063.   Variable         int crt_status_port
  18064.  
  18065.   Defined          vidsys.h
  18066.  
  18067.   Initialized in   WindowInitializeSystem()
  18068.  
  18069.   Purpose          This variable holds the value of the CRT status port.  This
  18070.                    port is used to test when it is safe to read or write
  18071.                    characters to the screen without producing snow.
  18072.  
  18073.   Modify Info      Should not be modified.
  18074.  
  18075.  
  18076.  
  18077.  
  18078.   Variable         int default_cursor_mode
  18079.  
  18080.   Defined          key.h
  18081.  
  18082.   Initialized in   WindowInitializeSystem()
  18083.  
  18084.   Purpose          Holds the mode that the WindowGet...() functions will
  18085.                    operate in when called.  The modes are either OVERSTRIKEMODE
  18086.                    or INSERTMODE.
  18087.  
  18088.   Default Value    OVERSTRIKEMODE.
  18089.  
  18090.   Modify Info      Can be modified at any time.
  18091.  
  18092.                    Example:
  18093.  
  18094.                    default_cursor_mode = INSERTMODE;
  18095.  
  18096.  
  18097.  
  18098.  Page 312                     The C Window Library                    Page 312
  18099.  
  18100.   Variable         int default_cursor_type[2]
  18101.  
  18102.   Defined          key.h
  18103.  
  18104.   Initialized in   WindowInitializeSystem()
  18105.  
  18106.   Purpose          Holds the cursor shapes for OVERSTRIKEMODE and INSERTMODE
  18107.                    input modes.
  18108.  
  18109.   Default Value    default_cursor_type[OVERSTRIKEMODE] is set to a block cursor.
  18110.                    default_cursor_type[INSERTMODE] is set to an underline
  18111.                    cursor.
  18112.  
  18113.   Modify Info      Can be modified at any time.
  18114.  
  18115.                    Example:
  18116.  
  18117.                    default_cursor_type[INSERTMODE] = CREATE_CURSOR_SHAPE(5,7);
  18118.  
  18119.  
  18120.  
  18121.  
  18122.  
  18123.   Variable         int default_screen_attr
  18124.  
  18125.   Defined in       vidsys.h
  18126.  
  18127.   Initialized in   WindowInitializeSystem()
  18128.  
  18129.   Purpose          Default video attribute used when any Video...() functions
  18130.                    are called to write to the screen.
  18131.  
  18132.   Default Value    7 (black background, white foreground).
  18133.  
  18134.   Modify Info      Can be modified at any time.
  18135.  
  18136.  
  18137.  
  18138.  
  18139.  
  18140.   Variable         int enhanced_keyboard
  18141.  
  18142.   Defined in       key.h
  18143.  
  18144.   Initialized in   WindowInitializeSystem()
  18145.  
  18146.   Purpose          Tells if an enhanced keyboard is attached.  If
  18147.                    enhanced_keyboard is 1, an enhanced keyboard is active,
  18148.                    otherwise if 0, the keyboard is not an enhanced keyboard.
  18149.  
  18150.   Modify Info      Can be modified safely.
  18151.  
  18152.  
  18153.  
  18154.  Page 313                     The C Window Library                    Page 313
  18155.  
  18156.   Variable         int explosion_speed[12]
  18157.  
  18158.   Defined in       window.h
  18159.  
  18160.   Initialized in   WindowInitializeSystem()
  18161.  
  18162.   Purpose          This array holds the number of milliseconds of delay for
  18163.                    each of the special effects supported in The C Window
  18164.                    Library.
  18165.  
  18166.   Default Value    10 (10 ms.), except for explosion_speed[BRICKS], which is 1
  18167.                    ms.
  18168.  
  18169.   Modify Info      Can be modified safely at anytime.  The way you would modify
  18170.                    the values is to use the special effects constants.  For
  18171.                    example:
  18172.  
  18173.                         explosion_speed[CONTRACT] = 5;
  18174.  
  18175.                    The above example changes the explosion delay for the
  18176.                    CONTRACT special effect to 5 ms.
  18177.  
  18178.  
  18179.  
  18180.  
  18181.  
  18182.   Variable         int flush_keyboard_flag.
  18183.  
  18184.   Defined in       key.h
  18185.  
  18186.   Initialized in   WindowInitializeSystem().
  18187.  
  18188.   Purpose          Tells if the keyboard buffer should be flushed whenever
  18189.                    the GET_KEY() or GET_ENHANCED_KEY() macros are called.  A
  18190.                    value of 1 means the buffer will be flushed.
  18191.  
  18192.   Default Value    0 (no flush).
  18193.  
  18194.   Modify Info      Can be modified at any time.
  18195.  
  18196.  
  18197.  
  18198.  
  18199.  
  18200.  
  18201.  
  18202.  
  18203.  
  18204.  
  18205.  
  18206.  
  18207.  
  18208.  
  18209.  
  18210.  Page 314                     The C Window Library                    Page 314
  18211.  
  18212.   Variable         VIDEO_CONFIG initial_video_startup
  18213.  
  18214.   Defined in       vidsys.h
  18215.  
  18216.   Initialized in   WindowInitializeSystem()
  18217.  
  18218.   Purpose          Structure that holds the video configuration when
  18219.                    WindowInitializeSystem() is called.
  18220.  
  18221.   Modify info      Should not be modified if the initial video startup is
  18222.                    desired when exiting an application.
  18223.  
  18224.  
  18225.  
  18226.  
  18227.  
  18228.  
  18229.   Variable         char input_mask_char
  18230.  
  18231.   Defined in       window.h
  18232.  
  18233.   Initialized in   WindowInitializeSystem()
  18234.  
  18235.   Purpose          Holds the mask character that is used for input routines.
  18236.                    The character defined in input_mask_char is used in input
  18237.                    masks to specify an input position in the edit field.  Refer
  18238.                    to the functions WindowGet..() functions for more
  18239.                    information concerning character masks.
  18240.  
  18241.   Default Value    '_'  (0x5F).
  18242.  
  18243.   Modify Info      Can be modified safely at any time, except when in the middle
  18244.                    of a user defined function that was called by The C Window
  18245.                    Library's input routines.
  18246.  
  18247.  
  18248.  
  18249.  
  18250.  
  18251.   Variable         void (*key_idle_func)(void)
  18252.  
  18253.   Defined in       key.h
  18254.  
  18255.   Initialized in   WindowInitializeSystem()
  18256.  
  18257.   Purpose          pointer that points to a function that is performed whenever
  18258.                    the GET_KEY() and GET_ENHANCED_KEY() macros do not have a
  18259.                    key ready to be processed.
  18260.  
  18261.   Modify Info      Can be modified at any time.
  18262.  
  18263.  
  18264.  
  18265.  
  18266.  Page 315                     The C Window Library                    Page 315
  18267.  
  18268.   Variable         unsigned (*key_intercept_func)(int which, unsigned keyval)
  18269.  
  18270.   Defined in       key.h
  18271.  
  18272.   Initialized in   WindowInitializeSystem()
  18273.  
  18274.   Purpose          pointer that points to a function which traps any keystrokes
  18275.                    that the GET_KEY() and GET_ENHANCED_KEY() macros will
  18276.                    return.
  18277.  
  18278.   Modify Info      Can be modified at any time.
  18279.  
  18280.  
  18281.  
  18282.  
  18283.  
  18284.  
  18285.   Variable         int max_video_pages
  18286.  
  18287.   Defined in       vidsys.h
  18288.  
  18289.   Initialized in   WindowInitializeSystem()
  18290.  
  18291.   Purpose          Total number of video pages detected by The C Window Library.
  18292.  
  18293.   Modify Info      Should not be modified unless a modification to the
  18294.                    screen_page_offset array was done.
  18295.  
  18296.  
  18297.  
  18298.  
  18299.  
  18300.   Variable         int max_window_rank
  18301.  
  18302.   Defined in       window.h
  18303.  
  18304.   Initialized in   WindowInitializeSystem()
  18305.  
  18306.   Purpose          Holds the rank value of the bottom-most (i.e. the
  18307.                    window that will have all other windows covering it).
  18308.  
  18309.   Modify Info      Do not modify.
  18310.  
  18311.  
  18312.  
  18313.  
  18314.  
  18315.  
  18316.  
  18317.  
  18318.  
  18319.  
  18320.  
  18321.  
  18322.  Page 316                     The C Window Library                    Page 316
  18323.  
  18324.   Variable         int min_window_rank
  18325.  
  18326.   Defined in       window.h
  18327.  
  18328.   Initialized in   WindowInitializeSystem()
  18329.  
  18330.   Purpose          Holds the rank value of the top-most visible window.
  18331.  
  18332.   Modify Info      Do not modify.
  18333.  
  18334.  
  18335.  
  18336.  
  18337.  
  18338.  
  18339.   Variable         int (*num_chars_entered_func)(char *string, int minchars)
  18340.  
  18341.   Defined in       key.h
  18342.  
  18343.   Arguments        string - string that was entered.
  18344.                    minchars - minimum number of characters expected.
  18345.  
  18346.   Initialized in   WindowInitializeSystem()
  18347.  
  18348.   Purpose          Pointer to user-defined function that will be executed when
  18349.                    the input manager detects that there were not enough
  18350.                    characters entered.
  18351.  
  18352.   Default Value    NULLFN.
  18353.  
  18354.  
  18355.  
  18356.  
  18357.  
  18358.   Variable         int (*num_chars_entered_func)(char *string, int minchars)
  18359.  
  18360.   Defined in       key.h
  18361.  
  18362.   Arguments        string - string that was entered.
  18363.                    minchars - minimum number of characters expected.
  18364.  
  18365.   Initialized in   WindowInitializeSystem()
  18366.  
  18367.   Purpose          Pointer to user-defined function that will be executed when
  18368.                    the input manager detects that there were not enough
  18369.                    characters entered.
  18370.  
  18371.   Default Value    NULLFN.
  18372.  
  18373.   Modify info      Can be modified at any time.
  18374.  
  18375.   Return Values    Must return DONT_PROCESS or ACCEPT_INPUT.
  18376.  
  18377.  
  18378.  Page 317                     The C Window Library                    Page 317
  18379.  
  18380.   Variable         int num_transparent_shadows[16]
  18381.  
  18382.   Defined in       window.h
  18383.  
  18384.   Initialized in   WindowInitializeSystem()
  18385.  
  18386.   Purpose          Array of the number of transparent shadows that are currently
  18387.                    displayed for each display page.
  18388.  
  18389.   Default Value    0 for each array element.
  18390.  
  18391.   Modify Info      Do not modify.
  18392.  
  18393.  
  18394.  
  18395.  
  18396.  
  18397.   Variable         WPOINTER orig_screen[16]
  18398.  
  18399.   Defined in       window.h
  18400.  
  18401.   Initialized in   WindowSaveInitial()
  18402.  
  18403.   Purpose          Array of windows created when WindowSaveInitial() is called.
  18404.                    The original screen for video page 0 is orig_screen[0], page
  18405.                    1 is orig_screen[1], etc.
  18406.   Modify Info      You can use any window function on the original screen,
  18407.                    except for ones that resize, move, hide, display, or close.
  18408.                    If you write strings to the original screen, you will
  18409.                    permanently destroy the contents of the original screen at
  18410.                    the positions that have been modified.
  18411.  
  18412.                    Example:
  18413.  
  18414.                    WindowWriteString(orig_screen[0],"123",1,1);
  18415.  
  18416.                    The above example writes "123" to the upper left hand corner
  18417.                    of the original screen of video page 0.
  18418.  
  18419.  
  18420.  
  18421.  
  18422.  
  18423.   Variable         int pagesize_
  18424.  
  18425.   Defined in       window.h
  18426.  
  18427.   Initialized in   WindowInitializeSystem()
  18428.  
  18429.   Purpose          Holds the size of a display page in bytes.
  18430.  
  18431.   Modify Info      Should not be modified unless The C Window Library did not
  18432.                    detect the correct video page size.
  18433.  
  18434.  Page 318                     The C Window Library                    Page 318
  18435.  
  18436.   Variable         int popmenu_button_press
  18437.  
  18438.   Defined in       cwlmouse.h
  18439.  
  18440.   Initialized in   MouseInitializeSystem()
  18441.  
  18442.   Purpose          Holds the current button mouse button to press to move the
  18443.                    highlight bar on popup menus.
  18444.  
  18445.   Default Value    MOUSELEFT_PRESS.
  18446.  
  18447.   Modify Info      Can be modified at any time.
  18448.  
  18449.  
  18450.  
  18451.  
  18452.  
  18453.   Variable         int (*reg_exp_error_func)(char *string, int nomatch);
  18454.  
  18455.   Defined in       key.h
  18456.  
  18457.   Arguments        string - string that was entered.
  18458.                    nomatch - position of the first non-matching character.
  18459.  
  18460.   Initialized in   WindowInitializeSystem()
  18461.  
  18462.   Purpose          Pointer to user-defined function that will be executed when
  18463.                    the input manager detects that there are illegal characters
  18464.                    in the string when it is compared to the regular
  18465.                    expression.  This function is only called when it is not
  18466.                    equal to NULLFN, and the CHECKREGEXP option is on.
  18467.  
  18468.   Default Value    NULLFN.
  18469.  
  18470.   Modify info      Can be modified at any time.
  18471.  
  18472.   Return Values    Must return DONT_PROCESS or ACCEPT_INPUT.
  18473.  
  18474.  
  18475.  
  18476.  
  18477.  
  18478.  
  18479.  
  18480.  
  18481.  
  18482.  
  18483.  
  18484.  
  18485.  
  18486.  
  18487.  
  18488.  
  18489.  
  18490.  Page 319                     The C Window Library                    Page 319
  18491.  
  18492.   Variable         unsigned char *screen_image[16]
  18493.  
  18494.   Defined in       window.h
  18495.  
  18496.   Initialized in   WindowInitializeSystem()
  18497.  
  18498.   Purpose          Used for internal window management.  Each pointer in the
  18499.                    screen_image array points to an image of the current
  18500.                    window organization of the screen. For example
  18501.                    screen_image[0] is a pointer to the current window "layout"
  18502.                    for video page 0.
  18503.  
  18504.   Modify Info      DO NOT modify this.  This array is VERY important when window
  18505.                    updates are done.
  18506.  
  18507.  
  18508.  
  18509.  
  18510.  
  18511.   Variable         unsigned char far *screen_page_offset[16]
  18512.  
  18513.   Defined in       window.h
  18514.  
  18515.   Initialized in   WindowInitializeSystem()
  18516.  
  18517.   Purpose          Array of starting addresses of each video page.
  18518.  
  18519.   Modify Info      You can modify if The C Window Library fails to detect video
  18520.                    pages that your video card may have.
  18521.  
  18522.                    Invalid video pages will set screen_page_offset[page] to a
  18523.                    far NULL pointer, where page is the invalid video page.
  18524.  
  18525.                    If there is a failure to detect video pages that your card
  18526.                    may have, you can use the MAKE_FAR_POINTER macro to
  18527.                    initialize.
  18528.                    Example: screen_page_offset[page] =
  18529.                             MAKE_FAR_POINTER(0xB000,0x2000);
  18530.  
  18531.                    where page is the page to initialize.  You should have the
  18532.                    documentation of the video card on hand so that you are sure
  18533.                    of the starting address of the video page.
  18534.  
  18535.                    You must also adjust the global variable max_video_pages to
  18536.                    reflect the new number of pages, and the pagesize_ variable
  18537.                    to reflect the size of each video page.
  18538.  
  18539.  
  18540.  
  18541.  
  18542.  
  18543.  
  18544.  
  18545.  
  18546.  Page 320                     The C Window Library                    Page 320
  18547.  
  18548.   Variable         int (*undef_akey_func)(char *string, unsigned key, int pos,
  18549.                                           int *newpos)
  18550.  
  18551.   Defined in       key.h
  18552.  
  18553.   Arguments        string - string currently entered.
  18554.                    key - key that was hit.
  18555.                    pos - position where cursor is in the input string.
  18556.  
  18557.   Purpose          Pointer to a function that is executed when a key that is not
  18558.                    defined in an input routines regular expression is pressed.
  18559.  
  18560.  
  18561.   Default Value    NULLFN.
  18562.  
  18563.   Modify Info      Can be modified at any time.
  18564.  
  18565.   Return Values    Refer to the manual for more information.
  18566.  
  18567.  
  18568.  
  18569.  
  18570.  
  18571.   Variable         int (*undef_fkey_func)(char *string, unsigned key, int pos,
  18572.                                           int *newpos)
  18573.  
  18574.   Defined in       key.h
  18575.  
  18576.   Arguments        string - string currently entered.
  18577.                    key - key that was hit.
  18578.                    pos - position where cursor is in the input string.
  18579.  
  18580.   Purpose          Pointer to a function that is executed when a key that is not
  18581.                    defined in an input routines regular expression is pressed.
  18582.  
  18583.  
  18584.   Purpose          Pointer to a function that is executed when a key that is not
  18585.                    defined in the window_edit_key array is pressed.
  18586.  
  18587.   Default Value    NULLFN.
  18588.  
  18589.   Modify Info      Can be modified at any time.
  18590.  
  18591.   Return Values    Refer to to the main documentation for more information.
  18592.  
  18593.  
  18594.  
  18595.  
  18596.  
  18597.  
  18598.  
  18599.  
  18600.  
  18601.  
  18602.  Page 321                     The C Window Library                    Page 321
  18603.  
  18604.   Variable         VWPOINTER virtual_window_ptrs[256]
  18605.  
  18606.   Defined in       window.h
  18607.  
  18608.   Purpose          Array of all initialized virtual window pointers.
  18609.  
  18610.   Modify Info      Do not modify.
  18611.  
  18612.  
  18613.  
  18614.  
  18615.  
  18616.   Variable         int visible_video_page
  18617.  
  18618.   Defined in       vidsys.h
  18619.  
  18620.   Initialized in   WindowInitializeSystem()
  18621.  
  18622.   Purpose          Current visible video page.
  18623.  
  18624.   Modify Info      Should be modified only by calling the SetVisibleVideoPage()
  18625.                    function.
  18626.  
  18627.  
  18628.  
  18629.  
  18630.  
  18631.   Variable         unsigned window_edit_key[12]
  18632.  
  18633.   Defined in       window.h
  18634.  
  18635.   Initialized in   WindowInitializeSystem()
  18636.  
  18637.   Purpose          Array of edit key definitions.  This array is used in the
  18638.                    window input routines.
  18639.  
  18640.   Modify Info      You can modify values in the array, provided that there are
  18641.                    no duplicate definitions, and there is a definition for a key
  18642.                    that terminates user input.  Refer to the GETTING INPUT FROM
  18643.                    WINDOWS section.
  18644.  
  18645.  
  18646.  
  18647.  
  18648.  
  18649.  
  18650.  
  18651.  
  18652.  
  18653.  
  18654.  
  18655.  
  18656.  
  18657.  
  18658.  Page 322                     The C Window Library                    Page 322
  18659.  
  18660.   Variable         int window_error_code
  18661.  
  18662.   Defined in       window.h
  18663.  
  18664.   Initialized in   WindowInitializeSystem()
  18665.  
  18666.   Purpose          Holds the last error that occurred as an integer.  You should
  18667.                    always check the value of window_error_code to determine what
  18668.                    has happened if a function fails.  All of the window and
  18669.                    virtual window functions return an error status when things
  18670.                    go wrong.  However, only selected functions from the Video...
  18671.                    family of functions set window_error_code.  The value in
  18672.                    window_error_code corresponds to the values found in
  18673.                    the file werror.h.
  18674.  
  18675.                    window_error_code does not reset itself if there are no
  18676.                    errors.
  18677.  
  18678.   Default Value    0.
  18679.  
  18680.   Modify Info      Safe to modify, but will always reset itself to an error
  18681.                    condition if a function fails.
  18682.  
  18683.  
  18684.  
  18685.  
  18686.  
  18687.   Variable         WPOINTER window_ptrs[256];
  18688.  
  18689.   Defined in       window.h
  18690.  
  18691.   Purpose          Array of all initialized windows.
  18692.  
  18693.   Modify Info      DO NOT modify.
  18694.  
  18695.  
  18696.  
  18697.  
  18698.  
  18699.   Variable         WPOINTER window_rank[257];
  18700.  
  18701.   Defined in       window.h
  18702.  
  18703.   Purpose          Array of all visible windows in rank order.
  18704.  
  18705.   Modify Info      DO NOT modify.
  18706.  
  18707.  
  18708.  
  18709.  
  18710.  
  18711.  
  18712.  
  18713.  
  18714.  Page 323                     The C Window Library                    Page 323
  18715.  
  18716.  
  18717.  
  18718.  
  18719.  
  18720.  
  18721.  
  18722.  
  18723.  
  18724.  
  18725.  
  18726.  
  18727.  
  18728.  
  18729.  
  18730.  
  18731.  
  18732.  
  18733.  
  18734.  
  18735.  
  18736.  
  18737.  
  18738.  
  18739.  
  18740.  
  18741.  
  18742.  
  18743.  
  18744.  
  18745.  
  18746.  
  18747.  
  18748.  
  18749.  
  18750.  
  18751.  
  18752.  
  18753.  Page 324                     The C Window Library                    Page 324
  18754.  
  18755.